diff options
Diffstat (limited to 'tests/aggregation')
| -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) |
