          self.assertEqual(len(people2), 1)
  
      def test_filter_annotation(self):
          books = Book.objects.annotate(
              is_book=Value(1, output_field=IntegerField())
          ).filter(is_book=1)
 
</s> remove                 model = field.model._meta.concrete_model
 </s> add                 try:
                    model = field.model._meta.concrete_model
                except AttributeError:
                    # QuerySet.annotate() may introduce fields that aren't
                    # attached to a model.
                    model = None </s> remove from django.db.models.functions import Lower
 </s> add from django.db.models.functions import Length, Lower
        lengths = Employee.objects.annotate(
            name_len=Length('first_name'),
        ).distinct('name_len').values_list('name_len', flat=True)
        self.assertSequenceEqual(lengths, [3, 7, 8])

          self.assertEqual(len(people2), 1)
  
        lengths = Employee.objects.annotate(
            name_len=Length('first_name'),
        ).distinct('name_len').values_list('name_len', flat=True)
        self.assertSequenceEqual(lengths, [3, 7, 8])

      def test_filter_annotation(self):
          books = Book.objects.annotate(
              is_book=Value(1, output_field=IntegerField())
          ).filter(is_book=1)
keep add keep keep keep keep
 Fixed #27800 -- Fixed QuerySet.annotate(Length(...)).distinct() crash. 
tests/annotations/tests.py