Register template filters on the fallback Jinja2 environment - #1243
Open
Sanjays2402 wants to merge 1 commit into
Open
Register template filters on the fallback Jinja2 environment#1243Sanjays2402 wants to merge 1 commit into
Sanjays2402 wants to merge 1 commit into
Conversation
When server.templates.path is configured, render_j2_template() creates a
custom Environment and registers the to_json filter on it. If a requested
template is not present in that directory, a second Environment is built
for the built-in templates, but no filters were registered on it, so any
built-in template using {{ ... | to_json }} (items.html, item.html,
stac_items.html) failed with TemplateAssertionError: No filter named
'to_json'.
Register the filter and global on the fallback environment as well, so a
partial custom templates directory transparently falls back to the
built-in templates.
Adds tests/unittests/test_ogc_api_util.py covering both the custom
template override and the fallback path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
render_j2_template()registers theto_jsonfilter on the Environment itcreates, but when a template is missing from a custom
server.templates.paththe fallback Environment for the built-in templates is created without it. Any
built-in template using
{{ ... | to_json }}(items.html,item.html,stac_items.html) then fails withTemplateAssertionError: No filter named 'to_json', so a partial customtemplates directory returns HTTP 500 instead of falling back cleanly.
This registers the filter and global on the fallback environment too.
Related Issue / Discussion
Closes #1236.
Additional Information
New
tests/unittests/test_ogc_api_util.pycovers both the custom-templateoverride and the fallback path; the fallback test fails with the exact reported
TemplateAssertionErrorwithout this change and passes with it.tests/unittestsis green (146 passed) and flake8 is clean on both changed files.
This change was prepared with AI assistance; the regression test was run locally
and fails without the fix.
Contributions and Licensing
(as per https://github.com/geopython/pycsw/blob/master/CONTRIBUTING.rst#contributions-and-licensing)