#33772: Queryset first() returns different result than queryset[0] when using
ExpressionWrapper
-------------------------------------+-------------------------------------
     Reporter:  Pablo Pissi          |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  closed
    Component:  Database layer       |                  Version:  3.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  invalid
     Keywords:                       |             Triage Stage:
  ExpressionWrapper,first,queryset   |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

 * status:  new => closed
 * resolution:   => invalid


Comment:

 This is happening because you don't explicitly define an ordering for your
 queryset so [https://www.percona.com/blog/2017/04/07/non-deterministic-
 order-select-limit/ the database can return whatever rows it wants] in the
 case of `[0]` while `.first()` explicitly order by `pk`
 
[https://github.com/django/django/blob/49b470b9187b6be60e573fed08c8f4a87f133750/django/db/models/query.py#L1035
 if no ordering is specified].

 Please TicketClosingReasons/UseSupportChannels before filing issues in
 this ticket tracker.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33772#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 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/01070181416dcf4e-3af5cd27-500a-400e-9cdb-7ae74f5d2948-000000%40eu-central-1.amazonses.com.

Reply via email to