mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #17424 -- annotate() + exclude() bug
The bug was already fixed by 01b9c3d519,
so only tests added.
At the same time promote_joins()'s uncoditional flag is gone, it isn't
needed for anything any more.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user