#34533: OuterRef not resolved as part oh ORDER BY clause
-------------------------------------+-------------------------------------
     Reporter:  REGNIER Guillaume    |                    Owner:  Jordan
                                     |  Bae
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  3.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  OuterRef, OrderBy    |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by REGNIER Guillaume):

 I've been working in and out on this for the last three weeks. I'm sorry I
 didn't claim the ticket...

 Here is a branch where the issue is solved:
 https://github.com/Alombaros/django/tree/ticket_34533_3_2

 I'm unsure on how to proceed.
 Previously, in the following query :
 
`MyModel.objects.annotate(foo=Subquery(MyOtherModel.objects.order_by(F("pk")).values("pk")[:1]))`
 The `F("pk")` was resolved as the `pk` of the outer query (`MyModel` in
 this case) which does not seems right to me.
 This was due to the order by expressions not being resolved until the last
 minute.

 I force the resolution when annotating a SubQuery so that the OuterRef can
 do its job but this made so `F` objects are resolved as field of the inner
 query.
 To me, this seems to be closer to the intended behavior because its what
 append when calling `.filter` or `.annotate` but if anyone used the prior
 behavior, thing will break

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34533#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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701883e41576b-a89f4083-9d21-44ca-bb0c-8ab3f9eff6f3-000000%40eu-central-1.amazonses.com.

Reply via email to