mirror of
https://github.com/django/django.git
synced 2025-08-03 02:23:12 +00:00
Improved table join handling for comparisons against NULL.
This fixes a broad class of bugs involving filters that look for missing related models and fields. Most of them don't seem to have been reported (the added tests cover the root cause). The exception is that this has also fixed #9868. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9979 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
68f81c873d
commit
923f78f504
4 changed files with 80 additions and 20 deletions
|
@ -13,6 +13,17 @@ class Choice(models.Model):
|
|||
def __unicode__(self):
|
||||
return u"Choice: %s in poll %s" % (self.choice, self.poll)
|
||||
|
||||
# A set of models with an inner one pointing to two outer ones.
|
||||
class OuterA(models.Model):
|
||||
pass
|
||||
|
||||
class OuterB(models.Model):
|
||||
data = models.CharField(max_length=10)
|
||||
|
||||
class Inner(models.Model):
|
||||
first = models.ForeignKey(OuterA)
|
||||
second = models.ForeignKey(OuterB, null=True)
|
||||
|
||||
__test__ = {'API_TESTS':"""
|
||||
# Regression test for the use of None as a query value. None is interpreted as
|
||||
# an SQL NULL, but only in __exact queries.
|
||||
|
@ -56,4 +67,16 @@ ValueError: Cannot use None as a query value
|
|||
>>> p2.choice_set.all()
|
||||
[]
|
||||
|
||||
# Querying across reverse relations and then another relation should insert
|
||||
# outer joins correctly so as not to exclude results.
|
||||
>>> obj = OuterA.objects.create()
|
||||
>>> OuterA.objects.filter(inner__second=None)
|
||||
[<OuterA: OuterA object>]
|
||||
>>> OuterA.objects.filter(inner__second__data=None)
|
||||
[<OuterA: OuterA object>]
|
||||
>>> _ = Inner.objects.create(first=obj)
|
||||
>>> Inner.objects.filter(first__inner__second=None)
|
||||
[<Inner: Inner object>]
|
||||
|
||||
|
||||
"""}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue