outer join regression over nullable foreign keys
|Reported by:||ikelly||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.5|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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:
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.
Change History (9)
comment:1 Changed 3 years ago by ikelly
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Summary changed from outer join regressing over nullable foreign keys to outer join regression over nullable foreign keys
comment:7 Changed 3 years ago by Anssi Kääriäinen <akaariai@…>
- Resolution set to fixed
- Status changed from new to closed