Fix incorrect behavior when a Jinja test returns Marker (#85264)

* Avoid Marker trip in plugin wrapper that causes unnecessary early template bailout.
* Remove spurious non-boolean result deprecation warning.
* Add test.

Co-authored-by: Matt Clay <matt@mystile.com>
pull/85270/head
Matt Davis 6 months ago committed by GitHub
parent 7da24ca7b0
commit 6198c7377f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -128,6 +128,9 @@ class JinjaPluginIntercept(c.MutableMapping):
def wrapper(*args, **kwargs) -> bool | Marker: def wrapper(*args, **kwargs) -> bool | Marker:
result = self._invoke_plugin(instance, *args, **kwargs) result = self._invoke_plugin(instance, *args, **kwargs)
if isinstance(result, Marker):
return result
if not isinstance(result, bool): if not isinstance(result, bool):
template = TemplateContext.current().template_value template = TemplateContext.current().template_value

@ -1074,3 +1074,9 @@ def test_unsafe_attr_access(template: str, expected: object) -> None:
with unittest.mock.patch.object(_TemplateConfig, 'sandbox_mode', _SandboxMode.ALLOW_UNSAFE_ATTRIBUTES): with unittest.mock.patch.object(_TemplateConfig, 'sandbox_mode', _SandboxMode.ALLOW_UNSAFE_ATTRIBUTES):
assert TemplateEngine().template(TRUST.tag(template)) == expected assert TemplateEngine().template(TRUST.tag(template)) == expected
def test_marker_from_test_plugin() -> None:
"""Verify test plugins can raise MarkerError to return a Marker, and that no warnings or deprecations are emitted."""
with emits_warnings(deprecation_pattern=[], warning_pattern=[]):
assert TemplateEngine(variables=dict(something=TRUST.tag("{{ nope }}"))).template(TRUST.tag("{{ (something is eq {}) is undefined }}"))

Loading…
Cancel
Save