#12851: Queryset "defer" won't work properly with select_related
---------------------------------------------------+------------------------
 Reporter:  ruosteinen                             |       Owner:  nobody    
   Status:  new                                    |   Milestone:            
Component:  Database layer (models, ORM)           |     Version:  1.2-beta  
 Keywords:  select_related, defer, nesting, query  |       Stage:  Unreviewed
Has_patch:  0                                      |  
---------------------------------------------------+------------------------
 Select_related and defer don't seem to work properly together. Consider
 following models in APP '''buggy'''.


 {{{
 from django.db import models

 class ProblemModel(models.Model):
     name = models.CharField(max_length=100)
     target = models.ForeignKey('Target', null=True)

 class Target(models.Model):
     location = models.CharField(max_length=100)

 }}}


 Even though Queryset API document the use of underscore in deferring, the
 following ends up in assertion error.


 {{{
 from buggy.models import Target, ProblemModel
 Target.objects.all().delete(); ProblemModel.objects.all().delete()

 tgt = Target.objects.create(location='Earth')
 pm = ProblemModel.objects.create(name='bug', target=tgt)

 pm =
 
ProblemModel.objects.select_related('target').defer('target__location').get(name='bug')

 assert pm.target.location == 'bug'


 }}}

 At least according to Queryset API docs, defer() is supposed to allow
 access to deferred fields even if they're not loaded initially.

 In addition pm.target is not of type Target_Deferred_location_deferred as
 it should be(?). There seem to be some other weirdness as well with
 select_related and defer but they'll probably be fixed once nesting works
 properly.

 This in Django 1.2 beta 1 SVN-12416


 I'll start working on a patch right away.

 -Tommi Penttinen-

-- 
Ticket URL: <http://code.djangoproject.com/ticket/12851>
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to