﻿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
16962	DoesNotExist when checking for related_name on OneToOneField	dan@…	nobody	"Reproducible test case:

{{{
class Example(models.Model):
    parent = models.OneToOneField('self', null=True, blank=True,
            related_name='child')

    def __unicode__(self):
        return ""%s"" % self.function
}}}

Console
{{{
>>> example = Example.objects.create()
>>> example2 = Example.objects.create(parent=example)
>>> example2.child # should return None, instead throws traceback
/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/django/db/models/fields/related.pyc in __get__(self, instance, instance_type)
    238             db = router.db_for_read(self.related.model, instance=instance)
--> 239             rel_obj = self.related.model._base_manager.using(db).get(**params)
    240             setattr(instance, self.cache_name, rel_obj)
    241             return rel_obj

/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/django/db/models/query.pyc in get(self, *args, **kwargs)
    347         if not num:
    348             raise self.model.DoesNotExist(""%s matching query does not exist.""
--> 349                     % self.model._meta.object_name)
    350         raise self.model.MultipleObjectsReturned(""get() returned more than one %s -- it returned %s! Lookup parameters were %s""
    351                 % (self.model._meta.object_name, num, kwargs))

DoesNotExist: Example matching query does not exist.
}}}

I considered sending in a patch to throw lines 238-240 in a try/except block, but I'm not sure that's the best way to solve this issue. I will submit something if a suggestion is made (I'm not super familiar with the Django codebase, so I might need some hand-holding)."	Bug	closed	Database layer (models, ORM)	1.3	Normal	duplicate			Unreviewed	0	0	0	0	0	0
