  from django.db.models import (
      BooleanField, CharField, Count, DateTimeField, ExpressionWrapper, F, Func,
      IntegerField, NullBooleanField, Q, Sum, Value,
  )
  from django.db.models.functions import Lower
  from django.test import TestCase, skipUnlessDBFeature
  
  from .models import (
      Author, Book, Company, DepartmentStore, Employee, Publisher, Store, Ticket,
  )
 
</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
from django.db.models.functions import Length, Lower
  from django.db.models import (
      BooleanField, CharField, Count, DateTimeField, ExpressionWrapper, F, Func,
      IntegerField, NullBooleanField, Q, Sum, Value,
  )
from django.db.models.functions import Length, Lower
  from django.test import TestCase, skipUnlessDBFeature
  
  from .models import (
      Author, Book, Company, DepartmentStore, Employee, Publisher, Store, Ticket,
  )
keep keep keep keep replace keep keep keep keep keep
 Fixed #27800 -- Fixed QuerySet.annotate(Length(...)).distinct() crash. 
tests/annotations/tests.py