#32297: QuerySet.get() method not working as expected with Window functions
-------------------------------------+-------------------------------------
     Reporter:  Jerin Peter George   |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

 * cc: Mariusz Felisiak, Simon Charette (added)
 * stage:  Unreviewed => Accepted


Comment:

 I'm going to provisionally accept this and ask Simon and Mariusz to have a
 look, since there does seem to be something amiss.

 Taking a similar case from one of my own projects, it's not just `values`
 (which
 [https://docs.djangoproject.com/en/3.1/topics/db/aggregation/#values might
 be/have been the issue]) the shows the strange behaviour, but straight
 iteration:

 {{{
 >>> list((t.pk, t.rank) for t in
 Task.objects.annotate(rank=Window(expression=Rank(),
 order_by=F("logged").desc()))[:10])
 [(1444, 1), (1443, 2), (1442, 3), (1441, 4), (1440, 5), (1439, 6), (1438,
 7), (1437, 8), (1436, 9), (1435, 10)]
 >>> Task.objects.annotate(rank=Window(expression=Rank(),
 order_by=F("logged").desc())).get(pk=1444).rank
 1
 >>> Task.objects.annotate(rank=Window(expression=Rank(),
 order_by=F("logged").desc())).get(pk=1442).rank
 1
 }}}

 I'm very much expecting the last line there to output 3.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32297#comment:5>
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/074.3349d6ee9b67e983fe3879890c4bf04d%40djangoproject.com.

Reply via email to