[Django] #34823: _assert_template_used fails with anonymous templates

2 views
Skip to first unread message

Django

unread,
Sep 8, 2023, 7:27:54 PM9/8/23
to django-...@googlegroups.com
#34823: _assert_template_used fails with anonymous templates
---------------------------------------------+------------------------
Reporter: Arian | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 4.2
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 |
---------------------------------------------+------------------------
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
```

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

Django

unread,
Sep 8, 2023, 7:31:01 PM9/8/23
to django-...@googlegroups.com
#34823: _assert_template_used fails with anonymous templates
-----------------------------------+--------------------------------------
Reporter: ArianK16a | Owner: nobody

Type: Bug | Status: new
Component: Testing framework | Version: 4.2
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 ArianK16a):

Suggested fix: https://github.com/django/django/pull/17237

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

Django

unread,
Sep 8, 2023, 7:36:43 PM9/8/23
to django-...@googlegroups.com
#34823: _assert_template_used fails with anonymous templates
-----------------------------------+--------------------------------------
Reporter: ArianK16a | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 4.2
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
-----------------------------------+--------------------------------------
Description changed by ArianK16a:

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
}}}

--

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

Reply all
Reply to author
Forward
0 new messages