#10710: limit() behaves erratically in a queryset where the model has two foreign keys ------------------------------------------+--------------------------------- Reporter: mrts | Owner: nobody Status: new | Milestone: 1.1 Component: Database layer (models, ORM) | Version: SVN Keywords: defer only | Stage: Unreviewed Has_patch: 0 | ------------------------------------------+--------------------------------- Given the models:
{{{ from django.db import models class Base(models.Model): name = models.CharField(max_length=10) lots_of_text = models.TextField() class Meta: abstract = True def __unicode__(self): return self.name class A(Base): a_field = models.CharField(max_length=10) class B(Base): b_field = models.CharField(max_length=10) class C(Base): a = models.ForeignKey(A) b = models.ForeignKey(B) is_published = models.BooleanField() }}} the following occurs: {{{ # all ok here: >>> from somewhere.models import A, B, C >>> results = C.objects.all().select_related() >>> results[0].a.id 2 >>> results[0].a.lots_of_text u'Sed ut perspiciatis unde omnis iste natus error...' # bizarre things happen: `id` and `lots_of_text` are swapped >>> results = C.objects.all().only('name', 'a', 'b').select_related() >>> results[0].a.lots_of_text 2 >>> results[0].a.id u'Sed ut perspiciatis unde omnis iste natus error...' # no luck in deferring two relations with only(): >>> C.objects.all().only('name', 'a', 'b').select_related().only('a__name', 'b__name') Traceback (most recent call last): ... FieldDoesNotExist: A has no field named 'b' # deferring a single relation with only works: >>> C.objects.all().only('name', 'a', 'b').select_related().only('a__name') [<C_Deferred_b_is_published_lots_of_text_name: c1>, ...] }}} -- Ticket URL: <http://code.djangoproject.com/ticket/10710> Django <http://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 -~----------~----~----~----~------~----~------~--~---