#13438: bug with isnull ForeignKey queries?
------------------------------------------+---------------------------------
 Reporter:  wkornewald                    |       Owner:  nobody    
   Status:  new                           |   Milestone:  1.2       
Component:  Database layer (models, ORM)  |     Version:  SVN       
 Keywords:                                |       Stage:  Unreviewed
Has_patch:  0                             |  
------------------------------------------+---------------------------------
 I'm not sure if this really is a bug. I have these models:

 {{{
 #!python
 from django.db import models

 class A(models.Model):
     number = models.IntegerField(null=True)

 class X(models.Model):
     fk = models.ForeignKey(A, null=True)
 }}}

 And when I run this query:

 {{{
 #!python
 X.objects.filter(fk=None)[:10]
 }}}

 The generated SQL is this:

 {{{
 #!sql
 SELECT "djangoappengine_x"."id", "djangoappengine_x"."fk_id"
 FROM "djangoappengine_x"
 LEFT OUTER JOIN "djangoappengine_a"
   ON ("djangoappengine_x"."fk_id" = "djangoappengine_a"."id")
 WHERE "djangoappengine_a"."id" IS NULL
 LIMIT 10
 }}}

 Shouldn't the generated query be this:

 {{{
 #!sql
 SELECT "djangoappengine_x"."id", "djangoappengine_x"."fk_id"
 FROM "djangoappengine_x"
 WHERE "djangoappengine_x"."fk_id" IS NULL
 LIMIT 10
 }}}

 Is there a reason why the query uses a LEFT OUTER JOIN on model A in this
 case (and the JOIN doesn't get trimmed) or is this just an incomplete edge
 case where the actual intention is to handle queries like
 `X.objects.filter(fk__number=None)`?

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