#18375: F() doesn't work as expected across multijoin relations
-------------------------------------+-------------------------------------
     Reporter:  FunkyBob             |                    Owner:  akaariai
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  1.4
  (models, ORM)                      |               Resolution:
     Severity:  Release blocker      |             Triage Stage:  Accepted
     Keywords:                       |      Needs documentation:  0
    Has patch:  1                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------

Comment (by akaariai):

 The previous patch had a problem where two chained filter calls would
 misuse joins. This was the failing test case:
 {{{
    Employee.objects.filter(
             company_ceo_set__num_employees=F('pk')
    ).filter(
 company_ceo_set__num_employees=F('company_ceo_set__num_employees')
    )
 }}}
 Now, first filter adds a join to company_ceo_set. The second filter's F()
 will reuse any joins, so the join to company_ceo_set is reused. And,
 finally the second company_ceo_set will reuse the join used by F(), and we
 have two separate filter() calls reusing the same join.

 The updated patch fixes this, and now F() expressions will behave just
 like other lookups in filter clauses when it comes to join reuse.

 Patch available here:
 
https://github.com/akaariai/django/commit/109a2b5598b7fc31e2b1d403e4da3a2a470748eb

 This widens the scope of users possibly hit. Any query where there is a
 pre-existing revfk (or m2m) join and which then gets a F() added targeting
 the same relation will behave differently. Seems somewhat likely scenario
 to me.

 To me it seems the patched version is doing what
 https://docs.djangoproject.com/en/dev/topics/db/queries/#spanning-multi-
 valued-relationships tells the behaviour should be.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/18375#comment:18>
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to