[Django] #36461: Sort keys in staticfiles.json to support reproducible builds

4 views
Skip to first unread message

Django

unread,
Jun 12, 2025, 6:45:43 AM6/12/25
to django-...@googlegroups.com
#36461: Sort keys in staticfiles.json to support reproducible builds
-------------------------------------+-------------------------------------
Reporter: matthews-noriker | Type:
| Cleanup/optimization
Status: new | Component:
| contrib.staticfiles
Version: 5.1 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
I am attempting to implement a build process whereby all my docker builds
are reproducible.
I am running the collectstatic management command (using the
ManifestStaticFilesStorage backend) as the final step of the Dockerfile,
however the ordering of the key-value pairs in the staticfiles.json are
not consistent across builds.

I propose that the keys in the staticfiles.json "paths" section are sorted
alphabetically to ensure that the staticfiles.json file generated for a
given set of static files is always consistent.
I do not believe that this will introduce a breaking change.

I am happy to submit a PR to implement this if accepted.


Here is the relevant code block:
https://github.com/django/django/blob/1ba5fe19ca221663e6a1e9391dbe726bb2baaf8a/django/contrib/staticfiles/storage.py#L498

{{{
def save_manifest(self):
self.manifest_hash = self.file_hash(
None,
ContentFile(json.dumps(sorted(self.hashed_files.items())).encode())
)
payload = {
"paths": self.hashed_files,
"version": self.manifest_version,
"hash": self.manifest_hash,
}
if self.manifest_storage.exists(self.manifest_name):
self.manifest_storage.delete(self.manifest_name)
contents = json.dumps(payload).encode()
self.manifest_storage._save(self.manifest_name,
ContentFile(contents))
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36461>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 13, 2025, 3:32:51 AM6/13/25
to django-...@googlegroups.com
#36461: Sort keys in staticfiles.json to support reproducible builds
-------------------------------------+-------------------------------------
Reporter: Matthew Stell | Owner: (none)
Type: | Status: closed
Cleanup/optimization |
Component: contrib.staticfiles | Version: 5.1
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* resolution: => duplicate
* status: new => closed

Comment:

Thank you for the ticket, this is a duplicate of #35846. To progress this
we need a way to reproduce so that we can later confirm the behavior is
fixed
--
Ticket URL: <https://code.djangoproject.com/ticket/36461#comment:1>
Reply all
Reply to author
Forward
0 new messages