Re: [Django] #36559: partialdef tag embedded in verbatim tag is treated as the source property for that named partial

13 views
Skip to first unread message

Django

unread,
Aug 18, 2025, 7:54:48 AMAug 18
to django-...@googlegroups.com
#36559: partialdef tag embedded in verbatim tag is treated as the source property
for that named partial
---------------------------------+------------------------------------
Reporter: Jacob Walls | Owner: (none)
Type: Bug | Status: new
Component: Template system | Version: dev
Severity: Release blocker | Resolution:
Keywords: partials | 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):

* cc: Carlton Gibson, Farhan Ali (added)
* keywords: => partials
* stage: Unreviewed => Accepted

Comment:

Thank you Jacob, I agree that we should treat as release blocker.
--
Ticket URL: <https://code.djangoproject.com/ticket/36559#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 18, 2025, 7:57:47 AMAug 18
to django-...@googlegroups.com
#36559: partialdef tag embedded in verbatim tag is treated as the source property
for that named partial
---------------------------------+--------------------------------------
Reporter: Jacob Walls | Owner: Farhan Ali
Type: Bug | Status: assigned
Component: Template system | Version: dev
Severity: Release blocker | Resolution:
Keywords: partials | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Farhan Ali):

* owner: (none) => Farhan Ali
* status: new => assigned

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

Django

unread,
Aug 18, 2025, 8:20:44 AMAug 18
to django-...@googlegroups.com
#36559: partialdef tag embedded in verbatim tag is treated as the source property
for that named partial
---------------------------------+--------------------------------------
Reporter: Jacob Walls | Owner: Farhan Ali
Type: Bug | Status: assigned
Component: Template system | Version: dev
Severity: Release blocker | Resolution:
Keywords: partials | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Old description:

> Although `partial` and `partialdef` are correctly ignored when rendered
> if embedded within `{% verbatim %}`, the `PartialTemplate.source`
> property is fooled, potentially impacting error reporting:
>
> {{{#!diff
> diff --git a/tests/template_tests/syntax_tests/test_partials.py
> b/tests/template_tests/syntax_tests/test_partials.py
> index a2cd3ae96a..6098531ed9 100644
> --- a/tests/template_tests/syntax_tests/test_partials.py
> +++ b/tests/template_tests/syntax_tests/test_partials.py
> @@ -484,6 +484,11 @@ class PartialTagTests(SimpleTestCase):
> {
> "partial_with_syntax_error": (
> "<h1>Title</h1>\n"
> + "{% verbatim %}\n"
> + "{% partialdef syntax_error_partial %}\n"
> + "VERBATIM\n"
> + "{% endpartialdef %}\n"
> + "{% endverbatim %}\n"
> "{% partialdef syntax_error_partial %}\n"
> " {% if user %}\n"
> " <p>User: {{ user.name }}</p>\n"
> @@ -506,6 +511,7 @@ class PartialTagTests(SimpleTestCase):
> self.assertIn("endpartialdef", exc_debug["during"])
> self.assertEqual(exc_debug["name"],
> "partial_with_syntax_error")
> self.assertIn("endif", exc_debug["message"].lower())
> + self.assertNotIn("verbatim",
> exc_debug["source_lines"][0][1])
>
> @setup(
> {
> }}}
>
> {{{#!py
> ======================================================================
> FAIL: test_partial_with_syntax_error_exception_info
> (template_tests.syntax_tests.test_partials.PartialTagTests.test_partial_with_syntax_error_exception_info)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
> File "/Users/jwalls/django/django/test/utils.py", line 458, in inner
> return func(*args, **kwargs)
> ^^^^^^^^^^^^^^^^^^^^^
> File "/Users/jwalls/django/tests/template_tests/utils.py", line 76, in
> inner
> func(self)
> File
> "/Users/jwalls/django/tests/template_tests/syntax_tests/test_partials.py",
> line 514, in test_partial_with_syntax_error_exception_info
> self.assertNotIn("verbatim", exc_debug["source_lines"][0][1])
> AssertionError: 'verbatim' unexpectedly found in '{% verbatim %}\n'
> }}}
> ----
> The use case presented here isn't very serious, so I'm loathe to really
> mark this as a release blocker, but as it's a new feature and that's our
> process, and I'm not sure if there are other more important uses of the
> source property, I'll start there.

New description:

Although `partial` and `partialdef` are correctly ignored when rendered if
embedded within `{% verbatim %}`, the `PartialTemplate.source` property is
fooled, potentially impacting error reporting:

{{{#!py
@setup(
{
"partial_embedded_in_verbatim": (
"{% verbatim %}\n"
"{% partialdef testing-name %}\n"
"{% endverbatim %}\n"
"{% partialdef testing-name %}\n"
"<p>Content</p>\n"
"{% endpartialdef %}\n"
),
},
test_once=True,
)
def test_partial_template_embedded_in_verbatim(self):
template =
self.engine.get_template("partial_embedded_in_verbatim")
partial_template = template.extra_data["partials"]["testing-name"]
self.assertIn("Content", partial_template.source)
}}}

{{{#!py
======================================================================
FAIL: test_partial_template_embedded_in_verbatim
(template_tests.syntax_tests.test_partials.PartialTagTests.test_partial_template_embedded_in_verbatim)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/jwalls/django/django/test/utils.py", line 458, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/jwalls/django/tests/template_tests/utils.py", line 58, in
inner
func(self)
File
"/Users/jwalls/django/tests/template_tests/syntax_tests/test_partials.py",
line 676, in test_partial_template_embedded_in_verbatim
self.assertIn("Content", partial_template.source)
AssertionError: 'Content' not found in ''
}}}
----
The use case presented here isn't very serious, so I'm loathe to really
mark this as a release blocker, but as it's a new feature and that's our
process, and I'm not sure if there are other more important uses of the
source property, I'll start there.

--
Comment (by Jacob Walls):

Replaced the sketched regression test, feel free to make further
improvements.
--
Ticket URL: <https://code.djangoproject.com/ticket/36559#comment:4>

Django

unread,
Aug 18, 2025, 8:58:34 AMAug 18
to django-...@googlegroups.com
#36559: partialdef tag embedded in verbatim tag is treated as the source property
for that named partial
---------------------------------+--------------------------------------
Reporter: Jacob Walls | Owner: Farhan Ali
Type: Bug | Status: assigned
Component: Template system | Version: dev
Severity: Release blocker | Resolution:
Keywords: partials | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Comment (by Carlton Gibson):

The same issue occurs with `{% comment %}` too. It's dependent on the
partial name being reused in the non-active block, that must appear first
in the source.

I'm not sure it's worth the price of entry — sometimes **don't do that**
is the right answer — but I'd be inclined to strip comment and verbatim
blocks before looking the match (if this usage is to be supported)
--
Ticket URL: <https://code.djangoproject.com/ticket/36559#comment:5>

Django

unread,
Aug 19, 2025, 6:11:08 AMAug 19
to django-...@googlegroups.com
#36559: partialdef tag embedded in verbatim tag is treated as the source property
for that named partial
---------------------------------+--------------------------------------
Reporter: Jacob Walls | Owner: Farhan Ali
Type: Bug | Status: assigned
Component: Template system | Version: dev
Severity: Release blocker | Resolution:
Keywords: partials | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Farhan Ali):

* has_patch: 0 => 1

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

Django

unread,
Aug 19, 2025, 6:13:41 AMAug 19
to django-...@googlegroups.com
#36559: partialdef tag embedded in verbatim tag is treated as the source property
for that named partial
---------------------------------+--------------------------------------
Reporter: Jacob Walls | Owner: Farhan Ali
Type: Bug | Status: assigned
Component: Template system | Version: dev
Severity: Release blocker | Resolution:
Keywords: partials | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Comment (by Farhan Ali):

We can add a parser approach for getting the source when in non-debug
mode, but I don’t think that is being used. Because the source is not
accessed when not in debug mode. If we decide to remove the parser
approach, we will just need to update the tests because the @setup
decorator runs in both debug and non-debug mode.
--
Ticket URL: <https://code.djangoproject.com/ticket/36559#comment:7>

Django

unread,
Sep 2, 2025, 11:44:23 AM (5 days ago) Sep 2
to django-...@googlegroups.com
#36559: partialdef tag embedded in verbatim tag is treated as the source property
for that named partial
---------------------------------+--------------------------------------
Reporter: Jacob Walls | Owner: Farhan Ali
Type: Bug | Status: assigned
Component: Template system | Version: dev
Severity: Release blocker | Resolution:
Keywords: partials | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Jacob Walls):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36559#comment:8>

Django

unread,
Sep 2, 2025, 1:28:50 PM (5 days ago) Sep 2
to django-...@googlegroups.com
#36559: partialdef tag embedded in verbatim tag is treated as the source property
for that named partial
---------------------------------+--------------------------------------
Reporter: Jacob Walls | Owner: Farhan Ali
Type: Bug | Status: assigned
Component: Template system | Version: dev
Severity: Release blocker | Resolution:
Keywords: partials | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Farhan Ali):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/36559#comment:9>

Django

unread,
Sep 2, 2025, 3:36:52 PM (5 days ago) Sep 2
to django-...@googlegroups.com
#36559: partialdef tag embedded in verbatim tag is treated as the source property
for that named partial
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Farhan
| Ali
Type: Bug | Status: assigned
Component: Template system | Version: dev
Severity: Release blocker | Resolution:
Keywords: partials | 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/36559#comment:10>

Django

unread,
Sep 3, 2025, 11:00:12 AM (4 days ago) Sep 3
to django-...@googlegroups.com
#36559: partialdef tag embedded in verbatim tag is treated as the source property
for that named partial
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Farhan
| Ali
Type: Bug | Status: closed
Component: Template system | Version: dev
Severity: Release blocker | Resolution: fixed
Keywords: partials | 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 <jacobtylerwalls@…>):

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

Comment:

In [changeset:"d82f25d3f0f4eb7be721a72d0e79a8d13d394d32" d82f25d3]:
{{{#!CommitTicketReference repository=""
revision="d82f25d3f0f4eb7be721a72d0e79a8d13d394d32"
Fixed #36559 -- Respected verbatim and comment blocks in
PartialTemplate.source.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36559#comment:12>

Django

unread,
Sep 3, 2025, 11:00:13 AM (4 days ago) Sep 3
to django-...@googlegroups.com
#36559: partialdef tag embedded in verbatim tag is treated as the source property
for that named partial
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Farhan
| Ali
Type: Bug | Status: assigned
Component: Template system | Version: dev
Severity: Release blocker | Resolution:
Keywords: partials | 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 Jacob Walls <jacobtylerwalls@…>):

In [changeset:"3485599ef08811e2fd066458aa083b2567f3cb84" 3485599]:
{{{#!CommitTicketReference repository=""
revision="3485599ef08811e2fd066458aa083b2567f3cb84"
Refs #36559 -- Ran template partial source tests in debug mode only.

Added a warning for accessing PartialTemplate.source when debugging is
disabled.
Thanks Sarah Boyce for the idea.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36559#comment:11>

Django

unread,
Sep 4, 2025, 12:19:31 PM (3 days ago) Sep 4
to django-...@googlegroups.com
#36559: partialdef tag embedded in verbatim tag is treated as the source property
for that named partial
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Farhan
| Ali
Type: Bug | Status: closed
Component: Template system | Version: dev
Severity: Release blocker | Resolution: fixed
Keywords: partials | 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 Jacob Walls <jacobtylerwalls@…>):

In [changeset:"34bd3ed944bf38792c631b55e581963d44d52284" 34bd3ed]:
{{{#!CommitTicketReference repository=""
revision="34bd3ed944bf38792c631b55e581963d44d52284"
Refs #36559, #35667 -- Used skip_file_prefixes in PartialTemplate.source
warning.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36559#comment:13>
Reply all
Reply to author
Forward
0 new messages