From f3cd99a28de1d55b98cec2a69935c5da54eb7465 Mon Sep 17 00:00:00 2001 From: Linus Heckemann Date: Tue, 15 Oct 2024 16:19:15 +0200 Subject: [PATCH] Fixed #35846 -- Improved reproducibility on staticfiles manifests. Previously, the paths would appear in a nondeterministic order in the resulting JSON file. I assume this would often reflect the order in which files are listed by the operating system, given dict's insertion order preservation, but there are probably many more factors affecting this. Sorting them results in more comparable results, smaller diffs and (depending on the environment) more efficient deployments. --- django/contrib/staticfiles/storage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py index 04a5edbd30..6918e1f755 100644 --- a/django/contrib/staticfiles/storage.py +++ b/django/contrib/staticfiles/storage.py @@ -504,7 +504,7 @@ class ManifestFilesMixin(HashedFilesMixin): } if self.manifest_storage.exists(self.manifest_name): self.manifest_storage.delete(self.manifest_name) - contents = json.dumps(payload).encode() + contents = json.dumps(payload, sort_keys=True).encode() self.manifest_storage._save(self.manifest_name, ContentFile(contents)) def stored_name(self, name):