summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Evans <d@evans.io>2014-03-22 21:57:01 +0000
committerTim Graham <timograham@gmail.com>2014-03-25 09:55:29 -0400
commitddcbde41eec12f7a84b00635cdbf1c93d4e4d297 (patch)
tree65c85761efa22801cb4c49e2082b5636429d18ba
parent24604844866a0b28122a1c47ac85072ea05b9b71 (diff)
[1.7.x] Fixed #22315 -- str/bytes mismatch in staticfiles
Previously, `ManifestFilesMixin.read_manifest` failed in Python 3 because `json.loads` accepts `str` not `bytes`. Backport of 86dcac4634 from master
-rw-r--r--django/contrib/staticfiles/storage.py5
-rw-r--r--tests/staticfiles_tests/tests.py5
2 files changed, 8 insertions, 2 deletions
diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py
index ede04fc2a5..fd114e45d5 100644
--- a/django/contrib/staticfiles/storage.py
+++ b/django/contrib/staticfiles/storage.py
@@ -292,7 +292,7 @@ class ManifestFilesMixin(HashedFilesMixin):
def read_manifest(self):
try:
with self.open(self.manifest_name) as manifest:
- return manifest.read()
+ return manifest.read().decode('utf-8')
except IOError:
return None
@@ -319,7 +319,8 @@ class ManifestFilesMixin(HashedFilesMixin):
payload = {'paths': self.hashed_files, 'version': self.manifest_version}
if self.exists(self.manifest_name):
self.delete(self.manifest_name)
- self._save(self.manifest_name, ContentFile(json.dumps(payload)))
+ contents = json.dumps(payload).encode('utf-8')
+ self._save(self.manifest_name, ContentFile(contents))
class _MappingCache(object):
diff --git a/tests/staticfiles_tests/tests.py b/tests/staticfiles_tests/tests.py
index 21ecf84bbc..4d2ba30c8c 100644
--- a/tests/staticfiles_tests/tests.py
+++ b/tests/staticfiles_tests/tests.py
@@ -662,6 +662,11 @@ class TestCollectionManifestStorage(TestHashedFiles, BaseCollectionTestCase,
storage.staticfiles_storage.manifest_version,
force_text(manifest_content))
+ def test_parse_cache(self):
+ hashed_files = storage.staticfiles_storage.hashed_files
+ manifest = storage.staticfiles_storage.load_manifest()
+ self.assertEqual(hashed_files, manifest)
+
# we set DEBUG to False here since the template tag wouldn't work otherwise
@override_settings(**dict(