diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-05-28 13:05:15 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-05-28 13:06:12 +0200 |
| commit | bd389a832aa1480fc76c3fb2bb6f92ea4209e378 (patch) | |
| tree | c8a996b9bbe3e346d64b513f0b2bf5f2f1be6065 | |
| parent | dc3234be48d17def4e951d678c0ec39c5ff94830 (diff) | |
[3.1.x] Refs #31040, Refs #31224 -- Prevented cycles in exceptions chain.
Async exception handling was raising an exception that was creating a
cycle in the exception chain (by re-raising an exception in
sync_to_async that was already being handled).
Thanks Chris Jerdonek for detailed analysis.
Backport of d94a9aa0557a459a5b9b7b82a8c043de14f8b1a0 from master
| -rw-r--r-- | django/core/handlers/base.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py index e7fbaf594e..ba7deb601b 100644 --- a/django/core/handlers/base.py +++ b/django/core/handlers/base.py @@ -179,6 +179,8 @@ class BaseHandler: response = wrapped_callback(request, *callback_args, **callback_kwargs) except Exception as e: response = self.process_exception_by_middleware(e, request) + if response is None: + raise # Complain if the view returned None (a common error). self.check_response(response, callback) @@ -200,6 +202,8 @@ class BaseHandler: response = response.render() except Exception as e: response = self.process_exception_by_middleware(e, request) + if response is None: + raise return response @@ -230,6 +234,8 @@ class BaseHandler: self.process_exception_by_middleware, thread_sensitive=True, )(e, request) + if response is None: + raise # Complain if the view returned None or an uncalled coroutine. self.check_response(response, callback) @@ -258,6 +264,8 @@ class BaseHandler: self.process_exception_by_middleware, thread_sensitive=True, )(e, request) + if response is None: + raise # Make sure the response is not a coroutine if asyncio.iscoroutine(response): @@ -323,13 +331,13 @@ class BaseHandler: def process_exception_by_middleware(self, exception, request): """ Pass the exception to the exception middleware. If no middleware - return a response for this exception, raise it. + return a response for this exception, return None. """ for middleware_method in self._exception_middleware: response = middleware_method(request, exception) if response: return response - raise + return None def reset_urlconf(sender, **kwargs): |
