Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when retrieving cache #119

Closed
cosmith opened this issue Dec 9, 2015 · 9 comments
Closed

Error when retrieving cache #119

cosmith opened this issue Dec 9, 2015 · 9 comments

Comments

@cosmith
Copy link

cosmith commented Dec 9, 2015

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
Copy link
Author

cosmith commented Dec 9, 2015

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
Copy link
Collaborator

auvipy commented Dec 9, 2015

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

@auvipy
Copy link
Collaborator

auvipy commented Dec 9, 2015

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

@auvipy
Copy link
Collaborator

auvipy commented Dec 9, 2015

would u plz share the code?

@cosmith
Copy link
Author

cosmith commented Dec 10, 2015

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
Copy link
Author

cosmith commented Dec 10, 2015

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
Copy link

gustavi commented Jan 7, 2016

Some news of Django 1.9 support ?

@cosmith
Copy link
Author

cosmith commented Jan 8, 2016

I upgraded to 3.3.1 and everything seems to be working fine so I'll close this. It was related to this bug encode/django-rest-framework#3628 in DRF.

@cosmith cosmith closed this as completed Jan 8, 2016
@auvipy
Copy link
Collaborator

auvipy commented Jan 8, 2016

haha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants