Opened 14 years ago
Closed 14 years ago
#17861 closed Bug (fixed)
Static files cache_key should handle spaces in filenames
| Reported by: | milosu | Owned by: | nobody |
|---|---|---|---|
| Component: | contrib.staticfiles | Version: | 1.4-beta-1 |
| Severity: | Release blocker | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
trying migrate my project to the Django 1.4c1, I get the following errors when running the storagefiles_tests test case:
======================================================================
ERROR: test_cache_invalidation (regressiontests.staticfiles_tests.tests.TestCollectionCachedStorage)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python26\Lib\site-packages\django_versions\Django-1.4c1\tests\regressiontests\staticfiles_tests\tests.py", lin
e 118, in setUp
self.run_collectstatic()
File "C:\Python26\Lib\site-packages\django_versions\Django-1.4c1\tests\regressiontests\staticfiles_tests\tests.py", lin
e 129, in run_collectstatic
ignore_patterns=['*.ignoreme'], **kwargs)
File "C:\Python26\lib\site-packages\django_versions\Django-1.4c1\django\core\management\__init__.py", line 150, in call
_command
return klass.execute(*args, **defaults)
File "C:\Python26\lib\site-packages\django_versions\Django-1.4c1\django\core\management\base.py", line 232, in execute
output = self.handle(*args, **options)
File "C:\Python26\lib\site-packages\django_versions\Django-1.4c1\django\core\management\base.py", line 371, in handle
return self.handle_noargs(**options)
File "C:\Python26\lib\site-packages\django_versions\Django-1.4c1\django\contrib\staticfiles\management\commands\collect
static.py", line 163, in handle_noargs
collected = self.collect()
File "C:\Python26\lib\site-packages\django_versions\Django-1.4c1\django\contrib\staticfiles\management\commands\collect
static.py", line 120, in collect
for original_path, processed_path, processed in processor:
File "C:\Python26\lib\site-packages\django_versions\Django-1.4c1\django\contrib\staticfiles\storage.py", line 192, in p
ost_process
self.cache.delete_many([self.cache_key(path) for path in paths])
File "C:\Python26\lib\site-packages\django_versions\Django-1.4c1\django\core\cache\backends\memcached.py", line 123, in delete_many
self._cache.delete_multi(map(l, keys))
File "build\bdist.win32\egg\memcache.py", line 336, in delete_multi
server_keys, prefixed_to_orig_key = self._map_and_prefix_keys(keys, key_prefix)
File "build\bdist.win32\egg\memcache.py", line 585, in _map_and_prefix_keys
self.check_key(str_orig_key, key_extra_len=key_extra_len)
File "build\bdist.win32\egg\memcache.py", line 958, in check_key
"Control characters not allowed")
MemcachedKeyCharacterError: Control characters not allowed
After a bit of digging, the root cause is a file which filename contains spaces,
e.g. in my case there is a file:
django/contrib/admin/static/admin/filebrowser/uploadify/Uploadify v2.1.0 Manual.pdf
The above test case is failing while trying to use the following cache key:
u'staticfiles:cache:admin\\filebrowser\\uploadify\\Uploadify v2.1.0 Manual.pdf'
This cache key is invalid under Memcached that I'm running.
Patch attached.
Attachments (2)
Change History (11)
by , 14 years ago
| Attachment: | staticfiles.diff added |
|---|
comment:1 by , 14 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 14 years ago
I'm missing warning due to this settings in settings.py:
CACHE_BACKEND = 'johnny.backends.memcached://127.0.0.1:11211/'
relative old app johnny cache with its own cache backend
comment:4 by , 14 years ago
Memcached does not allow spaces in cache keys, so I think the bug is clearly confirmed.
comment:5 by , 14 years ago
| Type: | Uncategorized → Bug |
|---|
comment:6 by , 14 years ago
I've changed my settings to:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
}
}
I'm still getting "MemcachedKeyCharacterError: Control characters not allowed" errors. See another attachment.
comment:7 by , 14 years ago
If this key is to be sanitized, should it be something that passes all requirements of django.core.cache.backends.base.BaseCache.validate_key ?
comment:8 by , 14 years ago
| Has patch: | set |
|---|
After talking with jezdez at the sprints - determined most straightforward fix is the md5 that path
I tried to reproduce it, but I only get a warning.