chibisov / drf-extensions

DRF-extensions is a collection of custom extensions for Django REST Framework
http://chibisov.github.io/drf-extensions/docs
MIT License
1.47k stars 208 forks source link

Error when retrieving cache #119

Closed cosmith closed 8 years ago

cosmith commented 8 years ago

Hi, I upgraded to Django 1.9 and the caching seems to be broken. I don't think you support 1.9 yet, but maybe someone here has an idea of where I can look? Thanks!

Environment:

Request Method: GET
Request URL: http://localhost:8000/markers-full/

Django Version: 1.9
Python Version: 2.7.10
Installed Applications:
(...
'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'bootstrapform',
 'django_extensions',
 'debug_toolbar',
 'rest_framework',
 'rest_framework.authtoken')
Installed Middleware:
('django.middleware.gzip.GZipMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'django.middleware.locale.LocaleMiddleware')

Traceback:

File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/usr/local/lib/python2.7/site-packages/django/views/decorators/csrf.py" in wrapped_view
  58.         return view_func(*args, **kwargs)

File "/usr/local/lib/python2.7/site-packages/rest_framework/viewsets.py" in view
  87.             return self.dispatch(request, *args, **kwargs)

File "/usr/local/lib/python2.7/site-packages/rest_framework/views.py" in dispatch
  466.             response = self.handle_exception(exc)

File "/usr/local/lib/python2.7/site-packages/rest_framework/views.py" in dispatch
  463.             response = handler(request, *args, **kwargs)

File "/usr/local/lib/python2.7/site-packages/rest_framework_extensions/cache/decorators.py" in inner
  43.                 kwargs=kwargs,

File "/usr/local/lib/python2.7/site-packages/rest_framework_extensions/cache/decorators.py" in process_cache_response
  60.         response = self.cache.get(key)

File "/usr/local/lib/python2.7/site-packages/django/core/cache/backends/locmem.py" in get
  54.                 return pickle.loads(pickled)

Exception Type: TypeError at /markers-full/
Exception Value: __new__() takes exactly 3 arguments (2 given)
cosmith commented 8 years ago

Someone here seems to have the same issue but that's all I could find: http://stackoverflow.com/questions/33356687/typeerror-from-django-cache

auvipy commented 8 years ago

Exception Value: new() takes exactly 3 arguments (2 given)

auvipy commented 8 years ago

dj 1.9 support would be added soon. but PR's are well come if you are proactive.

auvipy commented 8 years ago

would u plz share the code?

cosmith commented 8 years ago

I'd be happy to send a PR once I figure out what's going on!

This is my code, nothing fancy:

class MarkerCacheKey(DefaultKeyConstructor):
    query_params = bits.QueryParamsKeyBit('*')
    pagination = bits.PaginationKeyBit('*')

class MarkerFullViewSet(viewsets.ModelViewSet):
    """
    API endpoint that lists all markers in the db, without comments.
    """
    queryset = Marker.objects.all()
    serializer_class = MarkerFullSerializer
    pagination_class = LargeResultsSetPagination

    @cache_response(24 * 60 * 60, key_func=MarkerCacheKey())  # cache for one day
    def list(self, *args, **kwargs):
        return super(MarkerFullViewSet, self).list(*args, **kwargs)
cosmith commented 8 years ago

I have the same issue with a simple UserViewSet (with the default Django User model) and no custom key function, so it doesn't seem to come from my code.

gustavi commented 8 years ago

Some news of Django 1.9 support ?

cosmith commented 8 years ago

I upgraded to 3.3.1 and everything seems to be working fine so I'll close this. It was related to this bug https://github.com/tomchristie/django-rest-framework/issues/3628 in DRF.

auvipy commented 8 years ago

haha