﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
13839	select_related caches None for non-existent objects in reverse one-to-one relations	Shaun Cutts	Aymeric Augustin	"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'
}}}
"	Bug	closed	Database layer (models, ORM)	1.2	Normal	fixed		shaun@… Vlastimil Zíma tomasz.zielinski@… John Krukoff sebastian.goll@…	Accepted	1	0	0	0	0	0
