[Django] #36967: Use graphlib's TopologicalSorter to handle circular imports similar to migrations

3 views
Skip to first unread message

Django

unread,
Mar 4, 2026, 3:47:12 PM (2 days ago) Mar 4
to django-...@googlegroups.com
#36967: Use graphlib's TopologicalSorter to handle circular imports similar to
migrations
------------------------+------------------------------------------------
Reporter: blighj | Type: Cleanup/optimization
Status: new | Component: contrib.staticfiles
Version: 6.0 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------+------------------------------------------------
When ManifestStaticFilesStorage post processes files, it handles
dependency chains by looping until it sees no more changes in the files.
If there is a circular loop it will only try for 5 cycles by default and
then throw an error. This can be changed with the
`max_post_process_passes` attribute.

I propose we replace the looping approach with graphlib's
TopologicalSorter similar to the way it is used in migrations, this way
every file will only need to be processed once and we can detect and
handle circular imports without having to throw an error.
--
Ticket URL: <https://code.djangoproject.com/ticket/36967>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 4, 2026, 4:22:00 PM (2 days ago) Mar 4
to django-...@googlegroups.com
#36967: Use graphlib's TopologicalSorter to handle circular imports similar to
migrations
--------------------------------------+------------------------------------
Reporter: blighj | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: contrib.staticfiles | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Jacob Walls):

* stage: Unreviewed => Accepted

Comment:

Thanks for the migrations example. We also use it in `Media`.
--
Ticket URL: <https://code.djangoproject.com/ticket/36967#comment:1>

Django

unread,
Mar 4, 2026, 4:42:51 PM (2 days ago) Mar 4
to django-...@googlegroups.com
#36967: Use graphlib's TopologicalSorter to handle circular imports similar to
migrations
--------------------------------------+------------------------------------
Reporter: blighj | Owner: blighj
Type: Cleanup/optimization | Status: assigned
Component: contrib.staticfiles | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by blighj):

* owner: (none) => blighj
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/36967#comment:2>
Reply all
Reply to author
Forward
0 new messages