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..33fd8b3 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 | if hasattr(storage, "save_manifest"): |
| 679 | storage.staticfiles_storage.save_manifest() |
| 680 | else: |
| 681 | #Test will run correctly without previous version of ManifestFilesMixin |
| 682 | #That did post-processing and saving in one method |
| 683 | found_files = {} |
| 684 | for p in storage.staticfiles_storage.post_process(found_files): |
| 685 | pass |
| 686 | storage.staticfiles_storage.load_manifest() |
| 687 | self.assertEqual( |
| 688 | storage.staticfiles_storage.hashed_files["old_deleted_file"], |
| 689 | "record") |
| 690 | self.run_collectstatic() |
| 691 | self.assertNotIn("old_deleted_file", storage.staticfiles_storage.hashed_files) |
| 692 | |
672 | 693 | |
673 | 694 | # we set DEBUG to False here since the template tag wouldn't work otherwise |
674 | 695 | @override_settings(**dict( |