Opened 9 years ago
Closed 9 years ago
#25779 closed Cleanup/optimization (fixed)
Redundant try block in WSGIHandler
Reported by: | Attila Tovt | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Andrew Godwin | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In this code(https://github.com/django/django/blob/master/django/core/handlers/wsgi.py#L158-L165):
try: # Check that middleware is still uninitialized. if self._request_middleware is None: self.load_middleware() except Exception: # Unload whatever middleware we got self._request_middleware = None raise
It seems there is no need for this try block, because self._request_middleware
is being used as a flag of successful initialization completion.
Here where it gets assigned(https://github.com/django/django/blob/master/django/core/handlers/base.py#L73-L75):
# We only assign to this when initialization is complete as it is used # as a flag for initialization being complete. self._request_middleware = request_middleware
Maybe, there are some thread safety issues that I'm missing, in which case, I'm sorry for bothering.
Change History (5)
comment:1 by , 9 years ago
Cc: | added |
---|---|
Summary: | Redundant try block → Redundant try block in WSGIHandler |
comment:2 by , 9 years ago
It looks like this change predates the use of context managers in Django.
comment:3 by , 9 years ago
Triage Stage: | Unreviewed → Accepted |
---|
The try block should probably have been removed during this commit: [e0fce8706d31f]
Andrew, I tracked that addition to the patch you committed in #11193 [ba585a2c6d]. Any insight?