On Thu, 2010-12-16 at 11:30 -0800, Christophe Pettus wrote: > On Dec 16, 2010, at 11:14 AM, Luke Plant wrote: > > This isn't true if the field pointed to (i.e. primary key by default) > > allows NULL values - in that case a ForeignKey field with a NULL value > > can and should return a non-empty set of values when the related objects > > lookup is done. > > If I'm understanding your point, this isn't true; NULL does not match NULL on > a join.
With the SQL currently generated (which uses LEFT OUTER JOIN and an IS NULL comparison), with appropriate models and values matching the case I described, you can indeed get objects returned from the manager created by the ForeignRelatedObjectsDescriptor when you have a foreign key value to a nullable primary key. But having said that I'm not sure if its a case we need to worry about though, as it is pretty rare, and even the reverse descriptor ReverseSingleRelatedObjectDescriptor does not handle this case - the code explicitly assumes NULL in a FK value (None in the Python value) means 'no related object'. That being so, there is a case for arguing that ForeignRelatedObjectsDescriptor should not retrieve objects where the field pointed to is NULL - for consistency with the inverse operation. So I'm now in two minds. And both minds are tired, so I'm going to bed. Luke -- "Outside of a dog, a book is a man's best friend... inside of a dog, it's too dark to read." Luke Plant || http://lukeplant.me.uk/ -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-develop...@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.