diff options
| author | Luke Plant <L.Plant.98@cantab.net> | 2011-05-05 20:26:26 +0000 |
|---|---|---|
| committer | Luke Plant <L.Plant.98@cantab.net> | 2011-05-05 20:26:26 +0000 |
| commit | db5807bdb1f242cc928e2fdf7110cb20af34790f (patch) | |
| tree | 8b8b0ae4ed2fdee324d483e8a3fa4baceece0dab /tests | |
| parent | 970ae0162012185e441aa4a204c0f8b381975a47 (diff) | |
Fixed #15823 - incorrect join condition when combining Q objects
Thanks to dcwatson for the excellent report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16159 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/null_fk/models.py | 13 | ||||
| -rw-r--r-- | tests/regressiontests/null_fk/tests.py | 23 |
2 files changed, 36 insertions, 0 deletions
diff --git a/tests/regressiontests/null_fk/models.py b/tests/regressiontests/null_fk/models.py index 3cce319496..d96118c5c1 100644 --- a/tests/regressiontests/null_fk/models.py +++ b/tests/regressiontests/null_fk/models.py @@ -31,3 +31,16 @@ class Comment(models.Model): def __unicode__(self): return self.comment_text + +# Ticket 15823 + +class Item(models.Model): + title = models.CharField(max_length=100) + +class PropertyValue(models.Model): + label = models.CharField(max_length=100) + +class Property(models.Model): + item = models.ForeignKey(Item, related_name='props') + key = models.CharField(max_length=100) + value = models.ForeignKey(PropertyValue, null=True) diff --git a/tests/regressiontests/null_fk/tests.py b/tests/regressiontests/null_fk/tests.py index ab4bd522a0..2825cc9c8b 100644 --- a/tests/regressiontests/null_fk/tests.py +++ b/tests/regressiontests/null_fk/tests.py @@ -1,4 +1,5 @@ from django.test import TestCase +from django.db.models import Q from regressiontests.null_fk.models import * @@ -40,3 +41,25 @@ class NullFkTests(TestCase): ], transform = lambda c: (c.id, c.comment_text, repr(c.post)) ) + + def test_combine_isnull(self): + item = Item.objects.create(title='Some Item') + pv = PropertyValue.objects.create(label='Some Value') + item.props.create(key='a', value=pv) + item.props.create(key='b') # value=NULL + q1 = Q(props__key='a', props__value=pv) + q2 = Q(props__key='b', props__value__isnull=True) + + # Each of these individually should return the item. + self.assertEqual(Item.objects.get(q1), item) + self.assertEqual(Item.objects.get(q2), item) + + # Logically, qs1 and qs2, and qs3 and qs4 should be the same. + qs1 = Item.objects.filter(q1) & Item.objects.filter(q2) + qs2 = Item.objects.filter(q2) & Item.objects.filter(q1) + qs3 = Item.objects.filter(q1) | Item.objects.filter(q2) + qs4 = Item.objects.filter(q2) | Item.objects.filter(q1) + + # Regression test for #15823. + self.assertEqual(list(qs1), list(qs2)) + self.assertEqual(list(qs3), list(qs4)) |
