#34538: Incorrect query generated with on subquery WHERE depending on the order 
of
the Q() objects
-------------------------------------+-------------------------------------
     Reporter:  Alex                 |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  4.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  duplicate
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Hana Burtin):

 Looks like the issue is the priorities of operators in postgres:

 {{{
 postgres=# select false and false or true;
 ?column?
 t
 }}}


 {{{
 postgres=# select false and true or false;
 ?column?
 f
 }}}

 And I think we are expecting the same operation priority as python:

 {{{
 >>> 1 & 0 | 1
 <<< 1
 >>> 1 & 1 | 0
 <<< 1
 }}}

 To make things simpler: in python OR operators (`|` and `or`) are
 evaluated before  AND operators (`&` and `and`), while for postgres they
 have the same priority order.

 To solve this issue and similar ones, we might want to always add brackets
 around `OR` operator.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/34538#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018ffc8954f3-fd8edbb7-05ae-40c8-a6d4-ce05525505d1-000000%40eu-central-1.amazonses.com.

Reply via email to