Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid error handling in get_solo tag #137

Open
Viicos opened this issue Jul 1, 2024 · 1 comment · May be fixed by #138
Open

Invalid error handling in get_solo tag #137

Viicos opened this issue Jul 1, 2024 · 1 comment · May be fixed by #138
Assignees
Labels

Comments

@Viicos
Copy link
Contributor

Viicos commented Jul 1, 2024

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 Viicos mentioned this issue Jul 1, 2024
@johnthagen
Copy link
Collaborator

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

@johnthagen johnthagen added the bug label Jul 1, 2024
@Viicos Viicos linked a pull request Jul 1, 2024 that will close this issue
@johnthagen johnthagen self-assigned this Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants