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

Can't use a test decorated with @pass_context in select #1624

Closed
chris-chambers opened this issue Mar 17, 2022 · 0 comments
Closed

Can't use a test decorated with @pass_context in select #1624

chris-chambers opened this issue Mar 17, 2022 · 0 comments
Milestone

Comments

@chris-chambers
Copy link

When used from select, tests that are decorated with @pass_context fail with the error:

jinja2.exceptions.TemplateRuntimeError: Attempted to invoke a context test without context.

For example:

from jinja2 import Environment, pass_context

def main():
    env = Environment()
    env.tests["foo"] = is_foo
    output = env.from_string("""

    works: {{ "foo" is foo }}

    {%- for x in ["one", "foo" ] | select("foo") %}
    fails: {{ x }}
    {%- endfor %}

    """).render({})
    print(output)


@pass_context
def is_foo(ctx, s):
    return s == "foo"


if __name__ == "__main__":
    main()

Environment:

  • Python version: 3.10
  • Jinja version: 3.0.3
@CheeseCake87 CheeseCake87 changed the title Can't use a test decorated with @pass_context in select Can't use a test decorated with @pass_context in select Nov 27, 2024
@davidism davidism added this to the 3.1.5 milestone Dec 20, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants