﻿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
20091	outer join regression over nullable foreign keys	Erin Kelly	nobody	"We recently underwent an upgrade from Django 1.0.4 all the way to 1.5 and discovered a !QuerySet regression at some intermediate point under Oracle.  Given the models:

{{{
class Parent(models.Model):
    key = models.CharField(max_length=100)

class Child(models.Model):
    parent = models.ForeignKey(Parent, null=True)
}}}

Due to the way Oracle interprets empty strings as null, the following queries should both use an outer join and an IS NULL test:

{{{
Child.objects.filter(parent__key=None)
Child.objects.filter(parent__key=u'')
}}}

The first query correctly uses both an outer join and an IS NULL test.  The code responsible for transforming this lookup into an isnull is at [https://github.com/django/django/blob/master/django/db/models/sql/query.py#L1069].
The second query correctly uses an IS NULL test but with an inner join.  The code responsible for transforming this lookup into an isnull is at [https://github.com/django/django/blob/master/django/db/models/sql/where.py#L206].

I'm thinking that the latter code ought to be refactored into the former somehow."	Bug	closed	Database layer (models, ORM)	1.5	Normal	fixed			Unreviewed	0	0	0	0	0	0
