diff --git a/django/contrib/staticfiles/management/commands/collectstatic.py b/django/contrib/staticfiles/management/commands/collectstatic.py
index 0a14634..5a7d810 100644
a
|
b
|
class Command(NoArgsCommand):
|
87 | 87 | |
88 | 88 | if self.clear: |
89 | 89 | self.clear_dir('') |
| 90 | |
| 91 | if hasattr(self.storage, "on_collectstatic"): |
| 92 | self.storage.on_collectstatic(self) |
90 | 93 | |
91 | 94 | if self.symlink: |
92 | 95 | handler = self.link_file |
diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py
index fd114e4..9a7e25d 100644
a
|
b
|
class ManifestFilesMixin(HashedFilesMixin):
|
316 | 316 | self).post_process(*args, **kwargs) |
317 | 317 | for post_processed in all_post_processed: |
318 | 318 | yield post_processed |
| 319 | self.save_manifest() |
| 320 | |
| 321 | def save_manifest(self): |
319 | 322 | payload = {'paths': self.hashed_files, 'version': self.manifest_version} |
320 | 323 | if self.exists(self.manifest_name): |
321 | 324 | self.delete(self.manifest_name) |
322 | 325 | contents = json.dumps(payload).encode('utf-8') |
323 | 326 | self._save(self.manifest_name, ContentFile(contents)) |
324 | 327 | |
| 328 | def on_collectstatic(self, command): |
| 329 | self.hashed_files = OrderedDict() |
| 330 | |
325 | 331 | |
326 | 332 | class _MappingCache(object): |
327 | 333 | """ |
diff --git a/tests/staticfiles_tests/tests.py b/tests/staticfiles_tests/tests.py
index dec38e2..a0a482f 100644
a
|
b
|
class TestCollectionManifestStorage(TestHashedFiles, BaseCollectionTestCase,
|
669 | 669 | manifest = storage.staticfiles_storage.load_manifest() |
670 | 670 | self.assertEqual(hashed_files, manifest) |
671 | 671 | |
| 672 | def test_manifest_on_collectstatic(self): |
| 673 | """ |
| 674 | staticfiles.json manifest doesn't persist stale/deleted records, see #22557 |
| 675 | """ |
| 676 | self.assertNotIn("old_deleted_file", storage.staticfiles_storage.hashed_files) |
| 677 | storage.staticfiles_storage.hashed_files["old_deleted_file"] = "record" |
| 678 | storage.staticfiles_storage.save_manifest() |
| 679 | storage.staticfiles_storage.load_manifest() |
| 680 | self.assertEqual( |
| 681 | storage.staticfiles_storage.hashed_files["old_deleted_file"], |
| 682 | "record") |
| 683 | self.run_collectstatic() |
| 684 | self.assertNotIn("old_deleted_file", storage.staticfiles_storage.hashed_files) |
| 685 | |
672 | 686 | |
673 | 687 | # we set DEBUG to False here since the template tag wouldn't work otherwise |
674 | 688 | @override_settings(**dict( |