[Django] #33433: Avoid calling resolve() when unnecessary in technical_404_response

8 views
Skip to first unread message

Django

unread,
Jan 11, 2022, 11:47:59 PM1/11/22
to django-...@googlegroups.com
#33433: Avoid calling resolve() when unnecessary in technical_404_response
------------------------------------------------+------------------------
Reporter: Hrushikesh Vaidya | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (URLs) | Version: 4.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
As discussed in the comments of this
[https://github.com/django/django/pull/15286#issuecomment-1008798626 PR],
we can avoid calling `resolve(request.path)` in the
`technical_404_response` if `request.resolver_match` is already set.

This fix first checks if the resolver is `None` before calling
`resolve()`, and avoids the call entirely if we have already resolved.
{{{
caller = ''
if resolver_match is None:
try:
resolver_match = resolve(request.path)
except Http404:
pass

if resolver_match is not None:
caller = resolver_match._func_path
}}}

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

Django

unread,
Jan 12, 2022, 1:27:32 AM1/12/22
to django-...@googlegroups.com
#33433: Avoid calling resolve() when unnecessary in technical_404_response
-------------------------------------+-------------------------------------
Reporter: Hrushikesh Vaidya | Owner:
Type: | Hrushikesh Vaidya
Cleanup/optimization | Status: assigned

Component: Core (URLs) | Version: 4.0
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 Mariusz Felisiak):

* owner: nobody => Hrushikesh Vaidya
* status: new => assigned
* stage: Unreviewed => Accepted


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

Django

unread,
Jan 12, 2022, 2:23:40 AM1/12/22
to django-...@googlegroups.com
#33433: Avoid calling resolve() when unnecessary in technical_404_response
-------------------------------------+-------------------------------------
Reporter: Hrushikesh Vaidya | Owner:
Type: | Hrushikesh Vaidya
Cleanup/optimization | Status: assigned
Component: Core (URLs) | Version: 4.0
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
-------------------------------------+-------------------------------------

Comment (by Hrushikesh Vaidya):

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

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

Django

unread,
Jan 12, 2022, 2:38:09 AM1/12/22
to django-...@googlegroups.com
#33433: Avoid calling resolve() when unnecessary in technical_404_response
-------------------------------------+-------------------------------------
Reporter: Hrushikesh Vaidya | Owner:
Type: | Hrushikesh Vaidya
Cleanup/optimization | Status: assigned
Component: Core (URLs) | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


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

Django

unread,
Jan 12, 2022, 3:15:47 AM1/12/22
to django-...@googlegroups.com
#33433: Avoid calling resolve() when unnecessary in technical_404_response
-------------------------------------+-------------------------------------
Reporter: Hrushikesh Vaidya | Owner:
Type: | Hrushikesh Vaidya
Cleanup/optimization | Status: closed

Component: Core (URLs) | Version: 4.0
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"18a15bbc9c7df19fe38f252bcd62d5a3811e3451" 18a15bbc]:
{{{
#!CommitTicketReference repository=""
revision="18a15bbc9c7df19fe38f252bcd62d5a3811e3451"
Fixed #33433 -- Avoided unnecessary resolve() calls in
technical_404_response().

Thanks Keryn Knight for the initial patch.
}}}

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

Reply all
Reply to author
Forward
0 new messages