#13839: select_related caches None for non-existent objects in reverse 
one-to-one
relations
-----------------------------+----------------------------------------------
 Reporter:  shauncutts       |       Owner:            
   Status:  new              |   Milestone:            
Component:  ORM aggregation  |     Version:  1.2       
 Keywords:                   |       Stage:  Unreviewed
Has_patch:  0                |  
-----------------------------+----------------------------------------------
 Suppose we have the following:
 {{{
 class AM( models.Manager ):
     def get_query_set( self ):
         q = super( AM, self ).get_query_set()
         q = q.select_related( 'b' )
         return q

 class A( models.Model ):
     objects = AM()

     pass

 class B( A ):
     pass

 }}}
 Then when we create an A, and retrieve via the manager we have:
 {{{
 >>> A.objects.create()
 <A: A object>
 >>> a = A.objects.all()[ 0 ]
 >>> a.__dict__
 {'_b_cache': None,
  '_state': <django.db.models.base.ModelState object at 0x1fc6930>,
  'id': 2}
 }}}

 This causes problems, as {{{ a.b }}} yields None rather than triggering
 ObjectDoesNotExist, which causes problems -- e.g.:

 {{{
 >>> a.delete()
 /Users/shauncutts/dev/django/db/models/base.pyc in delete(self, using)
     645         # Find all the objects than need to be deleted.

     646         seen_objs = CollectedObjects()
 --> 647         self._collect_sub_objects(seen_objs)
     648
     649         # Actually delete the objects.


 /Users/shauncutts/dev/django/db/models/base.pyc in
 _collect_sub_objects(self, seen_objs, parent, nullable)
 --> 580                     sub_obj._collect_sub_objects(seen_objs, self,
 related.field.null)
     581             else:
     582                 # To make sure we can access all elements, we
 can't use the


 AttributeError: 'NoneType' object has no attribute '_collect_sub_objects'
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/13839>
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