          )
  
          # Regression for #10766 - Shouldn't be able to reference an aggregate
          # fields in an aggregate() call.
          self.assertRaises(
              FieldError,
              lambda: Book.objects.annotate(mean_age=Avg('authors__age')).annotate(Avg('mean_age'))
          )
  
      def test_empty_filter_count(self):
          self.assertEqual(
              Author.objects.filter(id__in=[]).annotate(Count("friends")).count(),
              0
 
</s> remove         self.assertRaises(
            FieldError,
            lambda: Book.objects.all().annotate(num_authors=Count('authors__id')).aggregate(Max('foo'))
        )
 </s> add         with self.assertRaises(FieldError):
            Book.objects.all().annotate(num_authors=Count('authors__id')).aggregate(Max('foo')) </s> remove         self.assertRaises(
            FieldError,
            lambda: Book.objects.all().aggregate(num_authors=Count('foo'))
        )
 </s> add         with self.assertRaises(FieldError):
            Book.objects.all().aggregate(num_authors=Count('foo')) </s> remove         self.assertRaises(
            ValueError,
            Book.objects.all().annotate,
            Avg('authors__age'), authors__age__avg=Avg('authors__age')
        )
 </s> add         with self.assertRaises(ValueError):
            Book.objects.all().annotate(Avg('authors__age'), authors__age__avg=Avg('authors__age')) </s> remove         self.assertRaises(ValueError, Author.objects.annotate, age=Avg('friends__age'))
 </s> add         with self.assertRaises(ValueError):
            Author.objects.annotate(age=Avg('friends__age')) </s> remove         self.assertRaises(
            FieldError,
            lambda: Book.objects.all().annotate(num_authors=Count('foo'))
        )
 </s> add         with self.assertRaises(FieldError):
            Book.objects.all().annotate(num_authors=Count('foo'))
        with self.assertRaises(FieldError):
            Book.objects.annotate(mean_age=Avg('authors__age')).annotate(Avg('mean_age'))
          )
  
          # Regression for #10766 - Shouldn't be able to reference an aggregate
          # fields in an aggregate() call.
        with self.assertRaises(FieldError):
            Book.objects.annotate(mean_age=Avg('authors__age')).annotate(Avg('mean_age'))
        with self.assertRaises(FieldError):
            Book.objects.annotate(mean_age=Avg('authors__age')).annotate(Avg('mean_age'))
        with self.assertRaises(FieldError):
            Book.objects.annotate(mean_age=Avg('authors__age')).annotate(Avg('mean_age'))
        with self.assertRaises(FieldError):
            Book.objects.annotate(mean_age=Avg('authors__age')).annotate(Avg('mean_age'))
  
      def test_empty_filter_count(self):
          self.assertEqual(
              Author.objects.filter(id__in=[]).annotate(Count("friends")).count(),
              0
keep keep keep keep replace replace replace replace keep keep keep keep keep
 Refs #26022 -- Used context manager version of assertRaises in tests. 
tests/aggregation_regress/tests.py