diff options
| author | Anv3sh <anveshgreat11@gmail.com> | 2022-06-16 21:34:13 +0530 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-06-20 08:51:26 +0200 |
| commit | d7f5bfd241666c0a76e90208da1e9ef81aec44db (patch) | |
| tree | 46ee5a0f15aead8589dcddc2b0d2c03ab431548a /django/http | |
| parent | 901a1691982cab76349d33e51b72c40120ec927a (diff) | |
Fixed #32969 -- Fixed pickling HttpResponse and subclasses.
Diffstat (limited to 'django/http')
| -rw-r--r-- | django/http/response.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/django/http/response.py b/django/http/response.py index 62b8b1c087..2bcd549f34 100644 --- a/django/http/response.py +++ b/django/http/response.py @@ -366,12 +366,31 @@ 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__, |
