#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:  0                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------
Changes (by akaariai):

 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0
 * type:  Uncategorized => Bug
 * stage:  Unreviewed => Accepted


Comment:

 To me this seems like a bug, or at least non-wanted behavior. Usually
 references inside one operation target the same alias, for example
 `filter(unter__available__gt=1, unter__exact=foo)` should target the same
 unter reference, while
 `filter(unter__available__gt=1).filter(unter__exact=foo)` should target
 different references.

 If this can be fixed at this point needs at least some consideration. The
 change could break existing queries, and there wouldn't be any way to get
 the original behavior back, as you can split one filter clause to two
 different filter operations.

 I have been thinking that it would be useful to be able to annotate the
 relations in the query. So, you could do:
 {{{
 
.annotate(unter_ref='unter').filter(unter_ref__available__gt=F('unter_ref__used'))
 OR
 .annotate(unter_ref1='unter',
 unter_ref2='unter').filter(unter_ref1__available__gt=F('unter_ref2__used'))
 }}}

 The first would generate the query you are looking for, the second would
 generate what you get now. However there is a long way to get to the point
 where you can use the annotate() like in the example.

 I am marking this as accepted. The reasoning is that the reference under
 the same .filter() call should target the same relation, and that the
 current behavior doesn't seem that useful. Backwards compatibility could
 turn this decision however.

 For the time being I can't figure out a way to generate the query you want
 without using qs.extra().

-- 
Ticket URL: <https://code.djangoproject.com/ticket/18375#comment:1>
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 this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to