You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using DRF 3.3.1, Django 1.8.7, and Python 2.7, with the default Django cache settings (LocMemCache), I discovered that my API endpoints failed when they were loaded from cache, with an error like:
Internal Server Error: /api/rest/v3/dockets/
Traceback (most recent call last):
File "/home/mlissner/.virtualenvs/courtlistener/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 108, in get_response
response = middleware_method(request)
File "/home/mlissner/.virtualenvs/courtlistener/local/lib/python2.7/site-packages/django/middleware/cache.py", line 134, in process_request
response = self.cache.get(cache_key, None)
File "/home/mlissner/.virtualenvs/courtlistener/local/lib/python2.7/site-packages/django/core/cache/backends/locmem.py", line 54, in get
return pickle.loads(pickled)
TypeError: __new__() takes exactly 3 arguments (2 given)
What happened was that the first time I loaded the page it worked, but the second time, it failed because it was loading from cache.
So....I set that value to 1 instead of the default of 2, and sure enough, the problem went away.
This is all a bit over my head, but my conclusion is that DRF, using the default pickle version....fails...sometimes. I assume this must have something to do with my code, but I don't have anything too interesting in there. This feels like a documentation problem, or a bug in Django, or even, in my code. I don't know, but it took a lot of investigation, so figured I should see if other more enlightened folks have thoughts/fixes/etc.
Thanks!
The text was updated successfully, but these errors were encountered:
Following up. I thought this might have something to do with my code since nobody else seems to have this issue, but I doubt it now. Here's the code that's causing this issue:
Yup! Just found it literally a second before your response, after days of looking for a solution! The secret was googling for getnewargs django. Do you know when we can expect this beautiful work to land in pip?
Using DRF 3.3.1, Django 1.8.7, and Python 2.7, with the default Django cache settings (
LocMemCache
), I discovered that my API endpoints failed when they were loaded from cache, with an error like:What happened was that the first time I loaded the page it worked, but the second time, it failed because it was loading from cache.
Asking on StackOverflow, I learned that there's an issue with version 2 of pickle that can cause this issue, and so I took the opportunity to switch my cache from
LocMemCache
toRedisCache
, which allows setting a customPICKLE_VERSION
.So....I set that value to 1 instead of the default of 2, and sure enough, the problem went away.
This is all a bit over my head, but my conclusion is that DRF, using the default pickle version....fails...sometimes. I assume this must have something to do with my code, but I don't have anything too interesting in there. This feels like a documentation problem, or a bug in Django, or even, in my code. I don't know, but it took a lot of investigation, so figured I should see if other more enlightened folks have thoughts/fixes/etc.
Thanks!
The text was updated successfully, but these errors were encountered: