Re: [Django] #34823: assertTemplateUsed() context manager crashes for templates without names.

13 views
Skip to first unread message

Django

unread,
Sep 20, 2023, 11:16:15 AM9/20/23
to django-...@googlegroups.com
#34823: assertTemplateUsed() context manager crashes for templates without names.
-----------------------------------+------------------------------------
Reporter: Arian | Owner: Arian
Type: Bug | Status: assigned
Component: Testing framework | Version: 4.2
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 Arian):

* needs_better_patch: 1 => 0
* needs_tests: 1 => 0


Old description:

> When template_names includes at least one None type the string join will
> fail.
> This occurs when a rendered template does not define a name.
>
> {{{
> Traceback (most recent call last):
> File "/home/.../admin-
> frontend/admin_frontend/admin_cash/tests/test_views.py", line 19, in
> test_get_context_data
> with self.assertTemplateUsed('admin_cash/bill_validator_logs.html'):
> File "/home/../3.10/lib/python3.10/site-
> packages/django/test/testcases.py", line 146, in __exit__
> self.test()
> File "/home/../3.10/lib/python3.10/site-
> packages/django/test/testcases.py", line 131, in test
> self.test_case._assert_template_used(
> File "/home/../3.10/lib/python3.10/site-
> packages/django/test/testcases.py", line 828, in _assert_template_used
> % (template_name, ", ".join(template_names)),
> TypeError: sequence item 0: expected str instance, NoneType found
> }}}

New description:

When template_names includes at least one None type the string join will
fail.
This occurs when a rendered template does not define a name.

{{{
Traceback (most recent call last):
File "/home/.../admin-
frontend/admin_frontend/admin_cash/tests/test_views.py", line 19, in
test_get_context_data
with self.assertTemplateUsed('admin_cash/bill_validator_logs.html'):
File "/home/../3.10/lib/python3.10/site-
packages/django/test/testcases.py", line 146, in __exit__
self.test()
File "/home/../3.10/lib/python3.10/site-
packages/django/test/testcases.py", line 131, in test
self.test_case._assert_template_used(
File "/home/../3.10/lib/python3.10/site-
packages/django/test/testcases.py", line 828, in _assert_template_used
% (template_name, ", ".join(template_names)),
TypeError: sequence item 0: expected str instance, NoneType found
}}}

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

--

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

Django

unread,
Sep 22, 2023, 4:51:33 AM9/22/23
to django-...@googlegroups.com
#34823: assertTemplateUsed() context manager crashes for templates without names.
-------------------------------------+-------------------------------------

Reporter: Arian | Owner: Arian
Type: Bug | Status: assigned
Component: Testing framework | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | 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/34823#comment:5>

Django

unread,
Sep 22, 2023, 5:46:43 AM9/22/23
to django-...@googlegroups.com
#34823: assertTemplateUsed() context manager crashes for templates without names.
-------------------------------------+-------------------------------------
Reporter: Arian | Owner: Arian
Type: Bug | Status: closed

Component: Testing framework | Version: 4.2
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | 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:"51d703a27fee518491adee1e07e2b857a90b2c8d" 51d703a2]:
{{{
#!CommitTicketReference repository=""
revision="51d703a27fee518491adee1e07e2b857a90b2c8d"
Fixed #34823 -- Fixed assertTemplateUsed() context manager crash on
unnamed templates.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34823#comment:6>

Django

unread,
Sep 22, 2023, 5:47:04 AM9/22/23
to django-...@googlegroups.com
#34823: assertTemplateUsed() context manager crashes for templates without names.
-------------------------------------+-------------------------------------
Reporter: Arian | Owner: Arian
Type: Bug | Status: closed
Component: Testing framework | Version: 4.2
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"7683c8635119b55eb04b18ab14b810582a4e8972" 7683c86]:
{{{
#!CommitTicketReference repository=""
revision="7683c8635119b55eb04b18ab14b810582a4e8972"
[5.0.x] Fixed #34823 -- Fixed assertTemplateUsed() context manager crash
on unnamed templates.

Backport of 51d703a27fee518491adee1e07e2b857a90b2c8d from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34823#comment:7>

Reply all
Reply to author
Forward
0 new messages