diff options
| author | Anvesh Mishra <anveshgreat11@gmail.com> | 2022-08-09 19:45:07 +0530 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-09-14 13:04:34 +0200 |
| commit | 6220c445c40a6a7f4d442de8bde2628346153963 (patch) | |
| tree | 36709f1275ebcdc6d0657605a8a09c8411e20667 /django/http | |
| parent | e14d08cd894e9d91cb5d9f44ba7532c1a223f458 (diff) | |
Fixed #29186 -- Fixed pickling HttpRequest and subclasses.
Diffstat (limited to 'django/http')
| -rw-r--r-- | django/http/request.py | 17 | ||||
| -rw-r--r-- | django/http/response.py | 2 |
2 files changed, 17 insertions, 2 deletions
diff --git a/django/http/request.py b/django/http/request.py index d65adce756..815544368b 100644 --- a/django/http/request.py +++ b/django/http/request.py @@ -51,6 +51,8 @@ class HttpRequest: _encoding = None _upload_handlers = [] + non_picklable_attrs = frozenset(["resolver_match", "_stream"]) + def __init__(self): # WARNING: The `WSGIRequest` subclass doesn't call `super`. # Any variable assignment made here should also happen in @@ -78,6 +80,21 @@ class HttpRequest: self.get_full_path(), ) + 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 __deepcopy__(self, memo): + obj = copy.copy(self) + for attr in self.non_picklable_attrs: + if hasattr(self, attr): + setattr(obj, attr, copy.deepcopy(getattr(self, attr), memo)) + memo[id(self)] = obj + return obj + @cached_property def headers(self): return HttpHeaders(self.META) diff --git a/django/http/response.py b/django/http/response.py index 7a0dd688f7..7c0db55a5d 100644 --- a/django/http/response.py +++ b/django/http/response.py @@ -370,12 +370,10 @@ class HttpResponse(HttpResponseBase): [ "resolver_match", # Non-picklable attributes added by test clients. - "asgi_request", "client", "context", "json", "templates", - "wsgi_request", ] ) |
