Skip to content

Node.__hash__ raises exception on all parsed input #1521

@klette

Description

@klette

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions