Opened 2 years ago

Last modified 2 years ago

#34104 closed New feature

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

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 (last modified by Daniel Wysocki)

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, despite the queries being equivalent.

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 (1)

comment:1 by Daniel Wysocki, 2 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top