Skip to content

Commit

Permalink
[1.7.x] Fixed #22315 -- str/bytes mismatch in staticfiles
Browse files Browse the repository at this point in the history
Previously, `ManifestFilesMixin.read_manifest` failed in Python 3
because `json.loads` accepts `str` not `bytes`.

Backport of 86dcac4 from master
  • Loading branch information
evansd authored and timgraham committed Mar 25, 2014
1 parent 2460484 commit ddcbde4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions django/contrib/staticfiles/storage.py
Expand Up @@ -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

Expand All @@ -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):
Expand Down
5 changes: 5 additions & 0 deletions tests/staticfiles_tests/tests.py
Expand Up @@ -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(
Expand Down

0 comments on commit ddcbde4

Please sign in to comment.