diff options
author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-04-12 09:46:18 +0200 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-04-12 18:52:43 +0200 |
commit | 173034b00589c083793d495e8b07e35be2cb1cf0 (patch) | |
tree | b242f05f2c5118a0986f1ffb088341b6909f47fb /django | |
parent | 280ca147af9cdfce1ca9cb14cc3c5527ff6c7a02 (diff) | |
download | django-173034b00589c083793d495e8b07e35be2cb1cf0.tar.gz |
Refs #34482 -- Reverted "Fixed #32969 -- Fixed pickling HttpResponse and subclasses."
This reverts commit d7f5bfd241666c0a76e90208da1e9ef81aec44db.
Thanks Márton Salomváry for the report.
Diffstat (limited to 'django')
-rw-r--r-- | django/http/response.py | 19 | ||||
-rw-r--r-- | django/template/response.py | 15 |
2 files changed, 8 insertions, 26 deletions
diff --git a/django/http/response.py b/django/http/response.py index 58993801e1..eecd972cd6 100644 --- a/django/http/response.py +++ b/django/http/response.py @@ -369,31 +369,12 @@ class HttpResponse(HttpResponseBase): """ streaming = False - non_picklable_attrs = frozenset( - [ - "resolver_match", - # Non-picklable attributes added by test clients. - "asgi_request", - "client", - "context", - "json", - "templates", - "wsgi_request", - ] - ) def __init__(self, content=b"", *args, **kwargs): super().__init__(*args, **kwargs) # Content is a bytestring. See the `content` property methods. self.content = content - def __getstate__(self): - obj_dict = self.__dict__.copy() - for attr in self.non_picklable_attrs: - if attr in obj_dict: - del obj_dict[attr] - return obj_dict - def __repr__(self): return "<%(cls)s status_code=%(status_code)d%(content_type)s>" % { "cls": self.__class__.__name__, diff --git a/django/template/response.py b/django/template/response.py index b4f0e171f1..c38b95e9de 100644 --- a/django/template/response.py +++ b/django/template/response.py @@ -8,9 +8,7 @@ class ContentNotRenderedError(Exception): class SimpleTemplateResponse(HttpResponse): - non_picklable_attrs = HttpResponse.non_picklable_attrs | frozenset( - ["template_name", "context_data", "_post_render_callbacks"] - ) + rendering_attrs = ["template_name", "context_data", "_post_render_callbacks"] def __init__( self, @@ -57,11 +55,16 @@ class SimpleTemplateResponse(HttpResponse): Raise an exception if trying to pickle an unrendered response. Pickle only rendered data, not the data used to construct the response. """ + obj_dict = self.__dict__.copy() if not self._is_rendered: raise ContentNotRenderedError( "The response content must be rendered before it can be pickled." ) - return super().__getstate__() + for attr in self.rendering_attrs: + if attr in obj_dict: + del obj_dict[attr] + + return obj_dict def resolve_template(self, template): """Accept a template object, path-to-template, or list of paths.""" @@ -142,9 +145,7 @@ class SimpleTemplateResponse(HttpResponse): class TemplateResponse(SimpleTemplateResponse): - non_picklable_attrs = SimpleTemplateResponse.non_picklable_attrs | frozenset( - ["_request"] - ) + rendering_attrs = SimpleTemplateResponse.rendering_attrs + ["_request"] def __init__( self, |