jqb / django-settings

Application to keep simple settings in database. Based on the contenttype framework.
BSD 3-Clause "New" or "Revised" License
83 stars 47 forks source link

String setting value with spaces #13

Closed rblack closed 11 years ago

rblack commented 11 years ago

String value with spaces like "Hello world" gives MemcachedKeyCharacterError: Control characters not allowed. As far as I see, django-settings trying to create key ':1:Hello world' which contains spaces and not allowed by Memcached.

Traceback: Environment:

Request Method: POST Request URL: http://127.0.0.1:8000/admin/django_settings/setting/19/

Django Version: 1.5.2 Python Version: 2.7.4 Installed Applications: ('admin_tools', 'admin_tools.theming', 'admin_tools.menu', 'admin_tools.dashboard', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'raven.contrib.django.raven_compat', 'djcelery', 'south', 'django_settings', 'django.contrib.admin', 'common', 'exodus', 'easy_thumbnails', 'gunicorn') Installed Middleware: ('django.middleware.cache.UpdateCacheMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.cache.FetchFromCacheMiddleware')

Traceback: File "/home/rblack/virtualenvs/protect3/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response

  1. response = callback(request, _callback_args, *_callback_kwargs) File "/home/rblack/virtualenvs/protect3/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
  2. return self.admin_site.admin_view(view)(_args, *_kwargs) File "/home/rblack/virtualenvs/protect3/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  3. response = view_func(request, _args, *_kwargs) File "/home/rblack/virtualenvs/protect3/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  4. response = view_func(request, _args, *_kwargs) File "/home/rblack/virtualenvs/protect3/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
  5. return view(request, _args, *_kwargs) File "/home/rblack/virtualenvs/protect3/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
  6. return bound_func(_args, *_kwargs) File "/home/rblack/virtualenvs/protect3/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  7. response = view_func(request, _args, *_kwargs) File "/home/rblack/virtualenvs/protect3/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
  8. return func(self, _args2, *_kwargs2) File "/home/rblack/virtualenvs/protect3/local/lib/python2.7/site-packages/django/db/transaction.py" in inner
  9. return func(_args, *_kwargs) File "/home/rblack/virtualenvs/protect3/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in change_view
  10. new_object = self.save_form(request, form, change=True) File "/home/rblack/virtualenvs/protect3/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in save_form
  11. return form.save(commit=False) File "/home/rblack/virtualenvs/protect3/local/lib/python2.7/site-packages/django_settings/forms.py" in save
  12. return self.setting_changed(instance) File "/home/rblack/virtualenvs/protect3/local/lib/python2.7/site-packages/django_settings/forms.py" in setting_changed
  13. django_settings.DataAPI.setting_changed(instance) File "/home/rblack/virtualenvs/protect3/local/lib/python2.7/site-packages/django_settings/dataapi.py" in setting_changed
  14. inst._set_cache_for(new_setting.name, new_setting.setting_object.value) File "/home/rblack/virtualenvs/protect3/local/lib/python2.7/site-packages/django_settings/dataapi.py" in _set_cache_for
  15. self.get._cache_set(value, name) File "/home/rblack/virtualenvs/protect3/local/lib/python2.7/site-packages/django_settings/cache.py" in _cache_set
  16. self.cache.set(key, origin_value) File "/home/rblack/virtualenvs/protect3/local/lib/python2.7/site-packages/django/core/cache/backends/memcached.py" in set
  17. self._cache.set(key, value, self._get_memcache_timeout(timeout)) File "/home/rblack/virtualenvs/protect3/local/lib/python2.7/site-packages/memcache.py" in set
  18. return self._set("set", key, val, time, min_compress_len) File "/home/rblack/virtualenvs/protect3/local/lib/python2.7/site-packages/memcache.py" in _set
  19. self.check_key(key) File "/home/rblack/virtualenvs/protect3/local/lib/python2.7/site-packages/memcache.py" in check_key
  20. "Control characters not allowed")

Exception Type: MemcachedKeyCharacterError at /admin/django_settings/setting/19/ Exception Value: Control characters not allowed

jqb commented 11 years ago

The real bug was that DataAPI._set_cache_for method was changing the order of name and value and was creating cache key from value instead of name. var 1.3-7 fixes that.