django/django · error · ValueError
The name '%s' could not be hashed with %r.
Error message
The name '%s' could not be hashed with %r.
What it means
Raised in HashedFilesMixin._hashed_name (the hashed-name resolution loop) when the computed cache_name keeps changing across passes and never converges within max_post_process_passes (default 5). The comment says intermediate files on disk may be corrupt; this guard prevents an infinite loop.
Source
Thrown at django/contrib/staticfiles/storage.py:533
if cache_name:
return cache_name
# No cached name found, recalculate it from the files.
intermediate_name = name
for i in range(self.max_post_process_passes + 1):
cache_name = self.clean_name(
self.hashed_name(name, content=None, filename=intermediate_name)
)
if intermediate_name == cache_name:
# Store the hashed name if there was a miss.
self.hashed_files[hash_key] = cache_name
return cache_name
else:
# Move on to the next intermediate file.
intermediate_name = cache_name
# If the cache name can't be determined after the max number of passes,
# the intermediate files on disk may be corrupt; avoid an infinite
# loop.
raise ValueError("The name '%s' could not be hashed with %r." % (name, self))
class ManifestFilesMixin(HashedFilesMixin):
manifest_version = "1.1" # the manifest format standard
manifest_name = "staticfiles.json"
manifest_strict = True
keep_intermediate_files = False
def __init__(self, *args, manifest_storage=None, **kwargs):
super().__init__(*args, **kwargs)
if manifest_storage is None:
manifest_storage = self
self.manifest_storage = manifest_storage
self.hashed_files, self.manifest_hash = self.load_manifest()
def read_manifest(self):
try:
with self.manifest_storage.open(self.manifest_name) as manifest:View on GitHub (pinned to b5388a3a80)
Solutions
- Clear STATIC_ROOT (delete the stale hashed/intermediate files) and re-run collectstatic.
- Inspect the CSS/JS referenced in the error for self-referential or chained url() paths and fix them.
- If you override HashedFilesMixin, ensure clean_name()/hashed_name() are deterministic (same input -> same output).
Example fix
# before -- stale hashed files cause non-converging passes manage.py collectstatic # -> ValueError could not be hashed # after -- wipe destination then re-run rm -rf /var/www/static/* manage.py collectstatic --noinput
Defensive patterns
Strategy: fallback
Validate before calling
import shutil from django.conf import settings # clear stale hashed/intermediate files before collectstatic shutil.rmtree(settings.STATIC_ROOT, ignore_errors=True)
Try / catch
from django.core.management import call_command
from django.core.management.base import CommandError
try:
call_command("collectstatic", no_input=True, clear=True)
except CommandError as e:
if "could not be hashed" in str(e):
call_command("collectstatic", no_input=True, clear=True)
else:
raise Prevention
- Run collectstatic with --clear to wipe stale hashed/intermediate files.
- Avoid self-referential url() loops in CSS that reference their own hashed output.
- Keep custom HashedFilesMixin overrides deterministic.
When it happens
Trigger: During collectstatic post-processing with keep_intermediate_files and hashed filenames, if each pass produces a different hashed name than the previous one for max_post_process_passes iterations. Typically caused by a CSS file referencing its own hashed output or a cyclic/chained reference that never stabilizes, or by corrupt intermediate files left in STATIC_ROOT.
Common situations: A CSS url() that points to a path that itself gets rewritten each pass (self-reference loop); leftover stale hashed files in STATIC_ROOT from a previous interrupted run; a custom storage overriding clean_name/hashed_name inconsistently.
Related errors
- The file '%s' could not be found with %r.
- Couldn't load manifest '%s' (version %s)
- Missing staticfiles manifest entry for '%s'
- Invalid Geometry loaded from pickled state.
- Transformed WKB was invalid.
AI-assisted analysis of django/django@b5388a3a80 (2026-08-10).
Data as JSON: /api/errors/01ff5404db81dc62.
Report an issue: GitHub.