-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Removing _closable_objects for pickling breaks response processing #1850
Comments
Want to try to track back the PR and conversation for originally adding it into REST framework in the first place. Personally I think the whole 'pickle'-for-caching responses is butt-ugly, but we just need to find whatever works most consistently with that. |
Looks to be a bug - text here states to remove this once we don't support 1.3... https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/response.py#L19 We don't support 1.3 now so those lines can be removed - feel free to go ahead and issue a pull request doing so. In any case those lines shouldn't be there - they should have been in |
Original issue was this: #1747. |
👍 |
@upmauro seeing the issue as well? |
I saw this problem last night when try to use caching in django 1.7. |
Adding the Before that we had:
@tomchristie the removal is supposed to be for the condition on Django being >= 1.4 I'm a bit lost at what's failing with the cache. Is the entire response cached ? |
What, why and where? We don't use pickle in any of our throttling implementations. How come we're tweaking a bit of private API? What fails if we don't do this, and why. Aside: Cursing at the hideousness of pickle as a design idea in general and at Django's caching middleware specfically for using it on response classes instead of just storing the response headers and body in the cache and recreating the object. Yuck. |
@tomchristie my bad, I edited my post because it was caching issue, not a throttling one. Can anyone give more context about when the issue does happen ? |
Two things here:
|
@tomchristie The py.test above was with current master with the |
Also possible that our tests are incorrect. We might instead want to be testing that our responses work okay together with Django's caching middleware, rather than testing against the low-level pickle API directly. |
Guys, i'm beginner and i'm not good to speak English, but i will try explain what happens with me. When i append, 'django.middleware.cache.UpdateCacheMiddleware', In MIDDLEWARE_CLASSES and use this in my views: @cache_page(60 * 15) The exception raised: NoReverseMatch at /api/ But in sometimes when i restart my sever and clean memcache, show AttributeError: 'Response' object has no attribute '_closable_objects'. I'm crazy? |
@upmauro thanks. That's exactly what I was looking for. This will help us reproduce the issue. |
@xordoquy great! if you need more informations, please tell-me |
@xordoquy chibisov/drf-extensions#32 - this is my original problem (read also comments for further info). |
@ondrowan thanks |
Any ideas? For now downgrade solve ? |
I find the problem in core, but i can't solve :(, someone can help-me ? |
@upmauro downgrade should solve this. Meanwhile I'll be working on this a bit more today |
By the way, adding the cache middleware makes the test suit fail heavily whether or not |
After upgrading DRF to 2.4.2 I hit this problem with Django 1.5.10 and my own caching code (not using django.middleware.cache). Workaround as suggested in DRF extensions github repo seems to be working for me, which is to explictly add _closable_objects to request AFTER fetching the response from the catch. Something like
|
Anyone want to figure out what part of the response object it's trying and failing to pickle, that's responsible for raising the error? /aside again. grumble grumble pickling entire arbitrary response object awful idea in the first place grumble grumble. |
About my problem i oppened another issue #1875 because i dont know if the same. |
Why is this closed? Picking-unpickling should not break the object. |
Because no-one's demonstrated that there's a regression. Looks feasible that it needs reopening, but let's start with a minimal reproducible case and take it from there. |
Summary: - Removes DjangoModelPermissions from the settings template. DjangoModelPermissions is not needed since the user actions are validated based on their organization allowed peers. There is no other permission model/group. DjangoModelPermissions rendered the non-GET actions unusable until now in the api (only admins could make such actions) whereas in the views, such actions were allowed (because the view used django forms instead of api callbacks) - Downgrades djangorestframework version to solve #1850 drf bug with pickling and caching. Bug was solved after version 3.0.4 which until now is not tested, so it's safer to downgrade. More info about the bug: encode/django-rest-framework#1850 - Fix documentation example for `then` rule - Adds PENDING in allowed Route statuses since the rules are applied asynchronously and this means that until applied, the Route will have to be in PENDING status. This was stated in commit 11171aa message but was not implemented Reviewers: #developers, zmousm Reviewed By: #developers, zmousm Subscribers: zmousm, #developers Differential Revision: https://phab.noc.grnet.gr/D5182
Here
_closable_objects
was added torendering_attrs
59d0a03#diff-21a03cd19b8422c334c33ec8da66e9c8R21Every rendering attribute is deleted in
__getstate__
method https://github.com/django/django/blob/1.7/django/template/response.py#L45But
_closable_objects
is used in base response handler:https://github.com/django/django/blob/1.7/django/core/handlers/base.py#L210
That's why after processing response from cache i get error like this:
I don't know, should i recreate this attribute by hand, or that's DRF error?
The text was updated successfully, but these errors were encountered: