From 93d1fdb1304ed5b2e5ea2e0f1e84db7fff5eb7fa Mon Sep 17 00:00:00 2001 From: Julien Phalip Date: Mon, 9 Apr 2012 00:43:08 +0000 Subject: Fixed #17877 -- Ensured that extra WHERE clauses get correctly ANDed when they contain OR operations. Thanks to Marek Brzóska for the report, to eleather for the test case and to Adrien Lemaire for the patch. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://code.djangoproject.com/svn/django/trunk@17880 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/extra_regress/tests.py | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests') diff --git a/tests/regressiontests/extra_regress/tests.py b/tests/regressiontests/extra_regress/tests.py index 67efb428dd..3fcafef5de 100644 --- a/tests/regressiontests/extra_regress/tests.py +++ b/tests/regressiontests/extra_regress/tests.py @@ -313,3 +313,34 @@ class ExtraRegressTests(TestCase): TestObject.objects.extra(where=["id > %s"], params=[obj.pk]), [''] ) + + def test_regression_17877(self): + """ + Ensure that extra WHERE clauses get correctly ANDed, even when they + contain OR operations. + """ + # Test Case 1: should appear in queryset. + t = TestObject(first='a', second='a', third='a') + t.save() + # Test Case 2: should appear in queryset. + t = TestObject(first='b', second='a', third='a') + t.save() + # Test Case 3: should not appear in queryset, bug case. + t = TestObject(first='a', second='a', third='b') + t.save() + # Test Case 4: should not appear in queryset. + t = TestObject(first='b', second='a', third='b') + t.save() + # Test Case 5: should not appear in queryset. + t = TestObject(first='b', second='b', third='a') + t.save() + # Test Case 6: should not appear in queryset, bug case. + t = TestObject(first='a', second='b', third='b') + t.save() + + self.assertQuerysetEqual( + TestObject.objects.extra( + where=["first = 'a' OR second = 'a'", "third = 'a'"], + ), + ['', ''] + ) -- cgit v1.3