[Django] #25779: Redundant try block

12 views
Skip to first unread message

Django

unread,
Nov 19, 2015, 2:47:06 PM11/19/15
to django-...@googlegroups.com
#25779: Redundant try block
--------------------------------------+--------------------
Reporter: Uran198 | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+--------------------
In this
code(https://github.com/django/django/blob/master/django/core/handlers/wsgi.py#L158-L165):
{{{#!python
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):
{{{#!python
# 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/25779>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 19, 2015, 3:09:29 PM11/19/15
to django-...@googlegroups.com
#25779: Redundant try block in WSGIHandler
-------------------------------------+-------------------------------------
Reporter: Uran198 | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* cc: andrewgodwin (added)
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Andrew, I tracked that addition to the patch you committed in #11193
[ba585a2c6d]. Any insight?

--
Ticket URL: <https://code.djangoproject.com/ticket/25779#comment:1>

Django

unread,
Nov 19, 2015, 4:15:42 PM11/19/15
to django-...@googlegroups.com
#25779: Redundant try block in WSGIHandler
-------------------------------------+-------------------------------------
Reporter: Uran198 | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by charettes):

It looks like this change predates the use of context managers in Django.

--
Ticket URL: <https://code.djangoproject.com/ticket/25779#comment:2>

Django

unread,
Nov 20, 2015, 2:35:56 AM11/20/15
to django-...@googlegroups.com
#25779: Redundant try block in WSGIHandler
--------------------------------------+------------------------------------

Reporter: Uran198 | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by claudep):

* stage: Unreviewed => Accepted


Comment:

The try block should probably have been removed during this commit:
[e0fce8706d31f]

--
Ticket URL: <https://code.djangoproject.com/ticket/25779#comment:3>

Django

unread,
Nov 20, 2015, 9:22:55 AM11/20/15
to django-...@googlegroups.com
#25779: Redundant try block in WSGIHandler
--------------------------------------+------------------------------------
Reporter: Uran198 | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Uran198):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/5693 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/25779#comment:4>

Django

unread,
Nov 20, 2015, 9:46:47 AM11/20/15
to django-...@googlegroups.com
#25779: Redundant try block in WSGIHandler
--------------------------------------+------------------------------------
Reporter: Uran198 | Owner: nobody
Type: Cleanup/optimization | Status: closed

Component: Core (Other) | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Attila Tovt <uran198@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"8092745593e2aa7b54c6de44d12a893772ace3e9" 80927455]:
{{{
#!CommitTicketReference repository=""
revision="8092745593e2aa7b54c6de44d12a893772ace3e9"
Fixed #25779 -- Removed redundant try block in WSGIHandler
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25779#comment:5>

Reply all
Reply to author
Forward
0 new messages