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

Node.__hash__ raises exception on all parsed input #1521

Closed
klette opened this issue Oct 27, 2021 · 0 comments · Fixed by #1522
Closed

Node.__hash__ raises exception on all parsed input #1521

klette opened this issue Oct 27, 2021 · 0 comments · Fixed by #1522
Milestone

Comments

@klette
Copy link
Contributor

klette commented Oct 27, 2021

I've looked into a regression in 6029341 where the Node.__hash__ method was changed from using object.__hash__ to it's
own implementation using Node.iter_fields().

Since the fields contain lists, the resulting tuple is not hashable.

Test case:

class TestHashing:
    def test_template_hash(self, env):
        template = env.parse("hash test")
        assert hash(template)

Output:

self = Template(body=[Output(nodes=[TemplateData(data='hash test')])])

    def __hash__(self):
>       return hash(tuple(self.iter_fields()))
E       TypeError: unhashable type: 'list'

This behaviour breaks some third party packages such as django-compressor. See django-compressor/django-compressor#1060

Environment:

  • Python version: 3.10
  • Jinja version: 3.0.x
@davidism davidism added this to the 3.0.3 milestone Nov 9, 2021
@davidism davidism closed this as completed Nov 9, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants