diff options
| author | Anders Kaseorg <andersk@mit.edu> | 2023-05-29 21:59:22 -0700 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-06-08 20:41:18 +0200 |
| commit | b81e974e9ea16bd693b194a728f77fb825ec8e54 (patch) | |
| tree | e0c816bf6751563791235ae95402e43af1acf6b1 /tests/xor_lookups | |
| parent | ee36e101e8f8c0acde4bb148b738ab7034e902a0 (diff) | |
Fixed #34604 -- Corrected fallback SQL for n-ary logical XOR.
An n-ary logical XOR Q(…) ^ Q(…) ^ … ^ Q(…) should evaluate to true
when an odd number of its operands evaluate to true, not when exactly
one operand evaluates to true.
Diffstat (limited to 'tests/xor_lookups')
| -rw-r--r-- | tests/xor_lookups/tests.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/xor_lookups/tests.py b/tests/xor_lookups/tests.py index a9cdf9cb31..d58d16cf11 100644 --- a/tests/xor_lookups/tests.py +++ b/tests/xor_lookups/tests.py @@ -19,6 +19,27 @@ class XorLookupsTests(TestCase): self.numbers[:3] + self.numbers[8:], ) + def test_filter_multiple(self): + qs = Number.objects.filter( + Q(num__gte=1) + ^ Q(num__gte=3) + ^ Q(num__gte=5) + ^ Q(num__gte=7) + ^ Q(num__gte=9) + ) + self.assertCountEqual( + qs, + self.numbers[1:3] + self.numbers[5:7] + self.numbers[9:], + ) + self.assertCountEqual( + qs.values_list("num", flat=True), + [ + i + for i in range(10) + if (i >= 1) ^ (i >= 3) ^ (i >= 5) ^ (i >= 7) ^ (i >= 9) + ], + ) + def test_filter_negated(self): self.assertCountEqual( Number.objects.filter(Q(num__lte=7) ^ ~Q(num__lt=3)), |
