  import re
  from collections import defaultdict
  from itertools import chain
  
  from django.conf import settings
  from django.db import models
  from django.db.migrations import operations
 
</s> remove from django.utils.topological_sort import CyclicDependencyError, stable_topological_sort
 </s> add  </s> remove from django.utils.topological_sort import stable_topological_sort
 </s> add  </s> remove                     dependency_graph[item].add(head)
 </s> add                     ts.add(item, head) </s> remove             dependency_graph.setdefault(head, set())
 </s> add             ts.add(head)
from graphlib import TopologicalSorter
  import re
  from collections import defaultdict
from graphlib import TopologicalSorter
  from itertools import chain
  
  from django.conf import settings
  from django.db import models
  from django.db.migrations import operations
keep add keep keep keep keep keep
 Fixed #32528 -- Replaced django.utils.topological_sort with graphlib.TopologicalSort().

graphlib.TopologicalSort() is available since Python 3.9. 
django/db/migrations/autodetector.py