Opened 3 years ago
Closed 3 years ago
#34104 closed New feature (needsinfo)
Making Q.__eq__ work regardless of ordering
| 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 )
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 (2)
comment:1 by , 3 years ago
| Description: | modified (diff) |
|---|
comment:2 by , 3 years ago
| Resolution: | → needsinfo |
|---|---|
| Status: | new → closed |
| Type: | Uncategorized → New feature |
Note:
See TracTickets
for help on using tickets.
Thanks for the report. The main question is: why do you need to change the current behavior? Is it problematic for Django itself? Please provide a rationale.