lazybird / django-solo

Helps working with singletons - things like global settings that you want to edit from the admin site.
Other
895 stars 85 forks source link

Invalid error handling in `get_solo` tag #137

Closed Viicos closed 3 weeks ago

Viicos commented 4 months ago

The following:

https://github.com/lazybird/django-solo/blob/e06af9a694ad04ff224354264818b6693a61de37/solo/templatetags/solo_tags.py#L20-L29

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()
johnthagen commented 4 months ago

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