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

 * has_patch:  0 => 1


Comment:

 What happens is that when a filter is added to query, the right hand value
 (F-obj in this case) is added first. At this point no joins exist. Then,
 the left hand side is added to the query (the lookup is resolved), but it
 can't reuse the join generated by the F-obj. At this point a new join is
 generated -> problems.

 Usually the F-obj will reuse any existing join, regardless if the join is
 generated in the same filter call or not. I am calling this a bug.
 Actually, this _must_ be a bug. Doing
 {{{
 .filter(unter__available__gt=0, unter__available__gt=F('unter__used'))
 }}}
 the F will target the existing join if the `unter__available__gt=0` is
 evaluated first. If not then it will generate a new join. This means that
 randomized dict ordering will cause random results from the above query.

 See https://github.com/akaariai/django/tree/ticket_18375 for one possible
 solution for this.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/18375#comment:3>
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to