#30942: first() and last() return same object (first in both cases) when the
order_by field is the same
-------------------------------------+-------------------------------------
               Reporter:  Tadas      |          Owner:  nobody
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  2.2
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 from datetime import datetime
 from django.db import models

 class Foo(models.Model):
     val = models.IntegerField()
     created_time = models.DateTimeField()

 created_time = datetime.now()

 foo1, _ = Foo.objects.get_or_create(val=1,
 defaults=dict(created_time=created_time))
 foo2, _ = Foo.objects.get_or_create(val=2,
 defaults=dict(created_time=created_time))

 assert Foo.objects.count() == 2

 foos = Foo.objects.all().order_by('created_time')
 print(foos.first().val, foos.last().val)  # prints -> 1 1

 assert foo1.val == foos.first().val
 assert foo2.val == foos.last().val  # FAILS

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30942>
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/049.149bf19dcbf0b9abf3cab3b429a071bb%40djangoproject.com.

Reply via email to