[Django] #36589: assertTemplateUsed asserts against template partial name regardless of origin

15 views
Skip to first unread message

Django

unread,
Sep 2, 2025, 12:33:03 PM9/2/25
to django-...@googlegroups.com
#36589: assertTemplateUsed asserts against template partial name regardless of
origin
-----------------------------+-------------------------------------------
Reporter: Jacob Walls | Type: Bug
Status: new | Component: Template system
Version: dev | Severity: Release blocker
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+-------------------------------------------
Currently, you can provide a named template partial like `"hello"` to
`assertTemplateUsed`, which scrupulously complies with its doc'd intention
to assert against names, but I can imagine wanting to provide the
"qualified" path like `my_page.html#hello`:

{{{#!diff
diff --git a/tests/test_utils/templates/template_used/partials.html
b/tests/test_utils/templates/template_used/partials.html
new file mode 100644
index 0000000000..5c8db3d657
--- /dev/null
+++ b/tests/test_utils/templates/template_used/partials.html
@@ -0,0 +1,5 @@
+{% partialdef hello %}
+<p>Hello</p>
+{% endpartialdef %}

diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py
index 9c22b61b4f..f7500ddc22 100644
--- a/tests/test_utils/tests.py
+++ b/tests/test_utils/tests.py
@@ -510,6 +510,14 @@ class
AssertTemplateUsedContextManagerTests(SimpleTestCase):
render_to_string("template_used/base.html")
render_to_string("template_used/base.html")

+ # passes
+ with self.assertTemplateUsed("hello"):
+ render_to_string("template_used/partials.html#hello")
+
+ # fails
+ with
self.assertTemplateUsed("template_used/partials.html#hello"):
+ render_to_string("template_used/partials.html#hello")
+
def test_nested_usage(self):
with self.assertTemplateUsed("template_used/base.html"):
with self.assertTemplateUsed("template_used/include.html"):
}}}

Notice the hint "Actual template(s) used: hello" does not point to the
origin, really.

{{{#!py
AssertionError: False is not true : Template
'template_used/partials.html#hello' was not a template used to render the
response. Actual template(s) used: hello
}}}

And if we regard the ''unqualified'' way as dubious, I'm suggesting we
should yank it before 6.0.

The fix doesn't look to be invasive. Curious to hear from others.
--
Ticket URL: <https://code.djangoproject.com/ticket/36589>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 2, 2025, 12:33:11 PM9/2/25
to django-...@googlegroups.com
#36589: assertTemplateUsed asserts against template partial name regardless of
origin
-----------------------------------+--------------------------------------
Reporter: Jacob Walls | Owner: (none)
Type: Bug | Status: new
Component: Testing framework | Version: dev
Severity: Release blocker | 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 Jacob Walls):

* component: Template system => Testing framework

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

Django

unread,
Sep 4, 2025, 9:16:44 AM9/4/25
to django-...@googlegroups.com
#36589: assertTemplateUsed asserts against template partial name regardless of
origin
-----------------------------------+------------------------------------
Reporter: Jacob Walls | Owner: (none)
Type: Bug | Status: new
Component: Testing framework | Version: dev
Severity: Release blocker | 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 Natalia Bidart):

* stage: Unreviewed => Accepted

Comment:

Hey Jacob, thanks for the report! I have reproduced how
`assertTemplateUsed` only matches the partial name (`hello`) and ignores
the qualified path (`template_used/partials.html#hello`).
I agree that using `template_used/partials.html#hello` should provide a
passing test assertion.
--
Ticket URL: <https://code.djangoproject.com/ticket/36589#comment:2>

Django

unread,
Sep 11, 2025, 12:48:46 PM9/11/25
to django-...@googlegroups.com
#36589: assertTemplateUsed asserts against template partial name regardless of
origin
-----------------------------------+------------------------------------
Reporter: Jacob Walls | Owner: k8en8r
Type: Bug | Status: assigned
Component: Testing framework | Version: dev
Severity: Release blocker | 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 k8en8r):

* owner: (none) => k8en8r
* status: new => assigned

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

Django

unread,
Sep 11, 2025, 4:57:15 PM9/11/25
to django-...@googlegroups.com
#36589: assertTemplateUsed asserts against template partial name regardless of
origin
-----------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Caitlin B
Type: Bug | Status: assigned
Component: Testing framework | Version: dev
Severity: Release blocker | 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 Caitlin B):

* has_patch: 0 => 1

Comment:

[https://github.com/django/django/pull/19847 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/36589#comment:4>

Django

unread,
Sep 15, 2025, 11:01:41 AM9/15/25
to django-...@googlegroups.com
#36589: assertTemplateUsed asserts against template partial name regardless of
origin
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Caitlin B
Type: Bug | Status: assigned
Component: Testing framework | Version: dev
Severity: Release blocker | 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 Jacob Walls):

* stage: Accepted => Ready for checkin

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

Django

unread,
Sep 15, 2025, 11:32:30 AM9/15/25
to django-...@googlegroups.com
#36589: assertTemplateUsed asserts against template partial name regardless of
origin
-----------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Caitlin B
Type: Bug | Status: assigned
Component: Testing framework | Version: dev
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-----------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* needs_better_patch: 0 => 1
* stage: Ready for checkin => Accepted

Comment:

Added some commentary about a potential issue with the code and the need
to use `subTest` when asserting over multiple things in the same unit
test.
--
Ticket URL: <https://code.djangoproject.com/ticket/36589#comment:6>

Django

unread,
Sep 15, 2025, 1:58:04 PM9/15/25
to django-...@googlegroups.com
#36589: assertTemplateUsed asserts against template partial name regardless of
origin
-----------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Caitlin B
Type: Bug | Status: assigned
Component: Testing framework | Version: dev
Severity: Release blocker | 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 Jacob Walls):

* needs_better_patch: 1 => 0

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

Django

unread,
Sep 15, 2025, 4:45:24 PM9/15/25
to django-...@googlegroups.com
#36589: assertTemplateUsed asserts against template partial name regardless of
origin
-----------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Caitlin B
Type: Bug | Status: closed
Component: Testing framework | Version: dev
Severity: Release blocker | 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 Jacob Walls <jacobtylerwalls@…>):

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

Comment:

In [changeset:"0e0b4214c350da9b627a67987b13ec334e1de033" 0e0b4214]:
{{{#!CommitTicketReference repository=""
revision="0e0b4214c350da9b627a67987b13ec334e1de033"
Fixed #36589 -- Made assertTemplateUsed/NotUsed track full path for
PartialTemplate.

Previously, assertTemplateUsed only matched partial names, ignoring
the template origin. This caused assertions on partials specified by
origin ("template.html#partial") to fail. Refs #36410.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36589#comment:8>

Django

unread,
Sep 15, 2025, 4:45:41 PM9/15/25
to django-...@googlegroups.com
#36589: assertTemplateUsed asserts against template partial name regardless of
origin
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Caitlin B
Type: Bug | Status: closed
Component: Testing framework | Version: dev
Severity: Release blocker | 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 Jacob Walls):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/36589#comment:9>
Reply all
Reply to author
Forward
0 new messages