diff options
| author | Anssi Kääriäinen <akaariai@gmail.com> | 2013-08-07 12:38:30 +0300 |
|---|---|---|
| committer | Anssi Kääriäinen <akaariai@gmail.com> | 2013-08-07 12:53:33 +0300 |
| commit | c7739e30b20f55c2b055b12a628bfb5c2228ba4e (patch) | |
| tree | bd577a2755edd316dc9503c6784c120139389d26 /tests | |
| parent | d53e574676ba0809394017f1f3a5bc24512e5bed (diff) | |
Fixed #17424 -- annotate() + exclude() bug
The bug was already fixed by 01b9c3d5193fe61b82ae8b26242a13fdec22f211,
so only tests added.
At the same time promote_joins()'s uncoditional flag is gone, it isn't
needed for anything any more.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/aggregation/tests.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py index e1a880585f..4d46cae766 100644 --- a/tests/aggregation/tests.py +++ b/tests/aggregation/tests.py @@ -596,3 +596,24 @@ class BaseAggregateTestCase(TestCase): self.assertEqual( max_books_per_rating, {'books_per_rating__max': 3}) + + def test_ticket17424(self): + """ + Check that doing exclude() on a foreign model after annotate() + doesn't crash. + """ + all_books = list(Book.objects.values_list('pk', flat=True).order_by('pk')) + annotated_books = Book.objects.order_by('pk').annotate(one=Count("id")) + + # The value doesn't matter, we just need any negative + # constraint on a related model that's a noop. + excluded_books = annotated_books.exclude(publisher__name="__UNLIKELY_VALUE__") + + # Try to generate query tree + str(excluded_books.query) + + self.assertQuerysetEqual(excluded_books, all_books, lambda x: x.pk) + + # Check internal state + self.assertIsNone(annotated_books.query.alias_map["aggregation_book"].join_type) + self.assertIsNone(excluded_books.query.alias_map["aggregation_book"].join_type) |
