Skip to content

PB-1615: Fix change form template variable lookup error #570

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

Merged
merged 1 commit into from
Apr 29, 2025

Conversation

msom
Copy link
Contributor

@msom msom commented Apr 29, 2025

We currently overwrite the change_form template globally and check for property_upload_url, which is only defined for a very few admin UI views (and even there only for part of the cases). Although django renders the template without showing an error, it pollutes the logs with a stack trace.

This PR introduces a template tag to get the context variable without triggering tracebacks if it is not defined.

Copy link
Member

@adk-swisstopo adk-swisstopo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://forum.djangoproject.com/t/proper-way-of-checking-variables-existing-in-templates/25678 suggests there exceptions are routine and best ignored. Without much Django experience I agree it nicer to avoid throwing the exception in the first place.

@register.simple_tag(takes_context=True)
def get_context_variable(context, name, default):
"""Retrieve a context variable from the template context, returning a default value if the
variable is not defined.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please explain in that function documentation why this is useful/needed.

@msom msom force-pushed the bug-PB-1615-property-upload-url branch from f0129b7 to b8e6b57 Compare April 29, 2025 13:51
@msom msom force-pushed the bug-PB-1615-property-upload-url branch from b8e6b57 to daf73d5 Compare April 29, 2025 13:52
@msom msom merged commit 13e8b1d into develop Apr 29, 2025
3 checks passed
@msom msom deleted the bug-PB-1615-property-upload-url branch April 29, 2025 14:11
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 this pull request may close these issues.

2 participants