{{{
#!python
(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.
--
Ticket URL: <https://code.djangoproject.com/ticket/34104>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
> The `Q.__eq__` method does not recognize the associativity/commutativity
> of connector operators. For instance
>
> {{{
> #!python
> (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.
New description:
The `Q.__eq__` method does not recognize the associativity/commutativity
of connector operators. For instance
{{{
#!python
(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.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/34104#comment:1>
* status: new => closed
* type: Uncategorized => New feature
* resolution: => needsinfo
Comment:
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/34104#comment:2>