Ticket #17424: ticket17424.2.diff

File ticket17424.2.diff, 1.2 KB (added by Łukasz Rekucki, 11 years ago)

Testcase rebased to master.

  • tests/aggregation/tests.py

    diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py
    index e1a8805..4d46cae 100644
    a b class BaseAggregateTestCase(TestCase):  
    596596        self.assertEqual(
    597597            max_books_per_rating,
    598598            {'books_per_rating__max': 3})
     599
     600    def test_ticket17424(self):
     601        """
     602        Check that doing exclude() on a foreign model after annotate()
     603        doesn't crash.
     604        """
     605        all_books = list(Book.objects.values_list('pk', flat=True).order_by('pk'))
     606        annotated_books = Book.objects.order_by('pk').annotate(one=Count("id"))
     607
     608        # The value doesn't matter, we just need any negative
     609        # constraint on a related model that's a noop.
     610        excluded_books = annotated_books.exclude(publisher__name="__UNLIKELY_VALUE__")
     611
     612        # Try to generate query tree
     613        str(excluded_books.query)
     614
     615        self.assertQuerysetEqual(excluded_books, all_books, lambda x: x.pk)
     616
     617        # Check internal state
     618        self.assertIsNone(annotated_books.query.alias_map["aggregation_book"].join_type)
     619        self.assertIsNone(excluded_books.query.alias_map["aggregation_book"].join_type)
Back to Top