Opened 2 years ago

Last modified 2 years ago

#34104 closed New feature

Making Q.__eq__ work regardless of ordering — at Initial Version

Reported by: Daniel Wysocki Owned by: nobody
Component: Database layer (models, ORM) Version: 4.1
Severity: Normal Keywords: query
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The Q.__eq__ method does not recognize the associativity/commutativity of connector operators. For instance

(Q(id=1) | Q(id=2)) == (Q(id=2) | Q(id=1))

evaluates to False.

A possible solution: add an attribute to django.utils.tree.Node to flag it as associative/commutative (maybe call it unordered). If that flag is set, cast self.children and other.children to sets instead of lists before comparing them.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top