lazybird/django-solo

Invalid error handling in `get_solo` tag

Closed this issue · 1 comments

The following:

model_class: type[SingletonModel] = apps.get_model(app_label, model_name)
if not model_class:
raise template.TemplateSyntaxError(_(
"Could not get the model name '%(model)s' from the application "
"named '%(app)s'" % {
'model': model_name,
'app': app_label,
}
))
return model_class.get_solo()

shouldn't happen, as get_model will raise a LookupError if the app and/or model doesn't exist. It should probably be:

try:
    model_class: type[SingletonModel] = apps.get_model(app_label, model_name)
except LookupError:
    raise template.TemplateSyntaxError(
        _(
            "Could not get the model name '{model}' from the application named '{app}'"
        ).format(model=model_name, app=app_label)
    )
return model_class.get_solo()

@Viicos If you are able to fix and add a test, that would be awesome.