Ticket #22557: 22557.2.diff

File 22557.2.diff, 2.7 KB (added by Ted, 10 years ago)

Updates following timgraham's comments on github

  • django/contrib/staticfiles/management/commands/collectstatic.py

    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):  
    8787
    8888        if self.clear:
    8989            self.clear_dir('')
     90           
     91        if hasattr(self.storage, "on_collectstatic"):
     92            self.storage.on_collectstatic(self)           
    9093
    9194        if self.symlink:
    9295            handler = self.link_file
  • django/contrib/staticfiles/storage.py

    diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py
    index fd114e4..9a7e25d 100644
    a b class ManifestFilesMixin(HashedFilesMixin):  
    316316                                   self).post_process(*args, **kwargs)
    317317        for post_processed in all_post_processed:
    318318            yield post_processed
     319        self.save_manifest()
     320   
     321    def save_manifest(self):
    319322        payload = {'paths': self.hashed_files, 'version': self.manifest_version}
    320323        if self.exists(self.manifest_name):
    321324            self.delete(self.manifest_name)
    322325        contents = json.dumps(payload).encode('utf-8')
    323326        self._save(self.manifest_name, ContentFile(contents))
    324327
     328    def on_collectstatic(self, command):
     329        self.hashed_files = OrderedDict()
     330
    325331
    326332class _MappingCache(object):
    327333    """
  • tests/staticfiles_tests/tests.py

    diff --git a/tests/staticfiles_tests/tests.py b/tests/staticfiles_tests/tests.py
    index dec38e2..a0a482f 100644
    a b class TestCollectionManifestStorage(TestHashedFiles, BaseCollectionTestCase,  
    669669        manifest = storage.staticfiles_storage.load_manifest()
    670670        self.assertEqual(hashed_files, manifest)
    671671
     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
    672686
    673687# we set DEBUG to False here since the template tag wouldn't work otherwise
    674688@override_settings(**dict(
Back to Top