#18165: Ordering by related field creates duplicates in resultant querysets
-------------------------------------+-------------------------------------
     Reporter:  dokterbob            |      Owner:  nobody
         Type:  Bug                  |     Status:  new
    Component:  Database layer       |    Version:  1.4
  (models, ORM)                      |   Keywords:  ordering, duplicates,
     Severity:  Normal               |  related
 Triage Stage:  Unreviewed           |  Has patch:  0
Easy pickings:  0                    |      UI/UX:  0
-------------------------------------+-------------------------------------
 When specifying an `ordering` property in a Model's Meta class, based on a
 field in a model with a ForeignKey relation to this model, duplicate
 objects are returned in the resulting queryset.

 A test application with failing unittest is attached to the report in a
 tarball. In summary, the following models and query code can be used to
 replicate this issue:

 {{{
     class TestModel(models.Model):
         class Meta:
             ordering = ('testrelated__field', )


     class TestRelated(models.Model):
         field = models.IntegerField()

         testmodel = models.ForeignKey(TestModel)
 }}}

 Now the following behaviour can be observed:

 {{{
     >>> o = TestModel()
     >>> o.save()
     >>> r1 = TestRelated(field=1, testmodel=o)
     >>> r2 = TestRelated(field=2, testmodel=o)
     >>> r1.save()
     >>> r2.save()
     >>> TestModel.objects.all()
     [<TestModel: 1>, <TestModel: 1>]
 }}}

 The behaviour has found to exist for the SQLite backend and might or might
 not occur with other database backends.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/18165>
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to