On May 14, 2010, at 5:43 AM, Tom Evans wrote: > On Thu, May 13, 2010 at 7:31 PM, Daniel Roseman <dan...@roseman.org.uk> wrote: >> >> >> On May 13, 5:35 pm, Peter Herndon <tphern...@gmail.com> wrote: >>> On May 13, 2010, at 10:29 AM, TallFurryMan wrote: >>> >>>> Hello Django users, >>> >>>> Is there a particular reason why using a related OneToOneField raises >>>> DoesNotExist instead of returning None? >>> >>> Any query you make that is supposed to return one or more instances, that >>> instead cannot find any results, returns a DoesNotExist. >> >> Not true - a .filter() query returns an empty QuerySet if no results >> are found. However a .get() query does raise DoesNotExist if it >> doesn't find anything - which is the exact equivalent of a >> OneToOneField lookup. > > To get super pedantic, he said 'any query that is supposed to return > one or more instances' would raise a DoesNotExist. You countered with > a .filter() query, which returns 0 or more instances. > > Cheers > > Tom
:) Indeed, I knew what I *meant* to say, but I must admit I didn't bother to look up the details before I wrote it all down. Further, I often forget that get_or_create returns the obj, boolean tuple, leading to the exact bug Daniel pointed out. I do that in my own code whenever I first use get_or_create again after an absence, and have to debug it. Mea culpa, I replied carelessly, points to Daniel for correcting me. But in *spirit* I was correct! :D Sadly, though, this is neither horseshoes nor hand-grenades, so close doesn't really count for much. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.