#29794: Duplicate object returned using filter -------------------------------------+------------------------------------- Reporter: Lars Solberg | Owner: nobody Type: Bug | Status: closed Component: Database layer | Version: 2.1 (models, ORM) | Severity: Normal | Resolution: invalid Keywords: duplicate, vacuum | Triage Stage: | Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Changes (by Claude Paroz):
* status: new => closed * resolution: => invalid Comment: Sorry, but I don't see anything shocking in what you showed us, even if it's a bit surprising. For example: {{{ In [6]: Server.objects.filter(name='server1').order_by('-name')[0].pk Out[6]: 2 In [7]: Server.objects.filter(name='server1').order_by('-name')[1].pk Out[7]: 2 }}} You are doing two queries with undefined ordering (as `name` is identical). So it's totally possible that the first query returns pk [1, 2], while the second query returns [2, 1]. It would be shocking if you'd obtain a similar result with one unique queryset: {{{ qs = Server.objects.filter(name='server1').order_by('-name') qs[0].pk => 2 qs[1].pk => 2 }}} -- Ticket URL: <https://code.djangoproject.com/ticket/29794#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 django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/062.c3f1cdf7a60c044235e86612ea2d6b94%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.