Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #22315 -- str/bytes mismatch in staticfiles

Previously, `ManifestFilesMixin.read_manifest` failed in Python 3
because `json.loads` accepts `str` not `bytes`.
  • Loading branch information...
commit 86dcac463437dce06ddcade10fa3f308436ba608 1 parent e3c4205
@evansd evansd authored timgraham committed
View
5 django/contrib/staticfiles/storage.py
@@ -292,7 +292,7 @@ def __init__(self, *args, **kwargs):
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 @@ def post_process(self, *args, **kwargs):
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):
View
5 tests/staticfiles_tests/tests.py
@@ -662,6 +662,11 @@ def test_loaded_cache(self):
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(
Please sign in to comment.
Something went wrong with that request. Please try again.