          )
  
      def test_field_error(self):
          # Bad field requests in aggregates are caught and reported
          self.assertRaises(
              FieldError,
              lambda: Book.objects.all().aggregate(num_authors=Count('foo'))
          )
  
          self.assertRaises(
              FieldError,
              lambda: Book.objects.all().annotate(num_authors=Count('foo'))
          )
 
</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')) </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: Author.objects.filter(firstname__exact="John")
        )
 </s> add         with self.assertRaises(FieldError):
            Author.objects.filter(firstname__exact="John") </s> remove         self.assertRaises(
            FieldError,
            lambda: Book.objects.annotate(mean_age=Avg('authors__age')).annotate(Avg('mean_age'))
        )
 </s> add         with self.assertRaises(FieldError):
            Book.objects.annotate(mean_age=Avg('authors__age')).annotate(Avg('mean_age')) </s> remove         self.assertRaises(
            TypeError,
            Article.objects.dates,
        )
 </s> add         with self.assertRaises(TypeError):
            Article.objects.dates()
        with self.assertRaises(FieldError):
            Book.objects.all().aggregate(num_authors=Count('foo'))
          )
  
      def test_field_error(self):
          # Bad field requests in aggregates are caught and reported
        with self.assertRaises(FieldError):
            Book.objects.all().aggregate(num_authors=Count('foo'))
        with self.assertRaises(FieldError):
            Book.objects.all().aggregate(num_authors=Count('foo'))
        with self.assertRaises(FieldError):
            Book.objects.all().aggregate(num_authors=Count('foo'))
        with self.assertRaises(FieldError):
            Book.objects.all().aggregate(num_authors=Count('foo'))
  
          self.assertRaises(
              FieldError,
              lambda: Book.objects.all().annotate(num_authors=Count('foo'))
          )
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