Changes between Version 1 and Version 4 of Ticket #36559


Ignore:
Timestamp:
Aug 18, 2025, 7:20:37 AM (5 weeks ago)
Author:
Jacob Walls
Comment:

Replaced the sketched regression test, feel free to make further improvements.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #36559

    • Property Cc Carlton Gibson Farhan Ali added
    • Property Keywords partials added
    • Property Triage Stage UnreviewedAccepted
    • Property Owner set to Farhan Ali
    • Property Status newassigned
  • Ticket #36559 – Description

    v1 v4  
    11Although `partial` and `partialdef` are correctly ignored when rendered if embedded within `{% verbatim %}`, the `PartialTemplate.source` property is fooled, potentially impacting error reporting:
    22
    3 {{{#!diff
    4 diff --git a/tests/template_tests/syntax_tests/test_partials.py b/tests/template_tests/syntax_tests/test_partials.py
    5 index a2cd3ae96a..6098531ed9 100644
    6 --- a/tests/template_tests/syntax_tests/test_partials.py
    7 +++ b/tests/template_tests/syntax_tests/test_partials.py
    8 @@ -484,6 +484,11 @@ class PartialTagTests(SimpleTestCase):
    9          {
    10              "partial_with_syntax_error": (
    11                  "<h1>Title</h1>\n"
    12 +                "{% verbatim %}\n"
    13 +                "{% partialdef syntax_error_partial %}\n"
    14 +                "VERBATIM\n"
    15 +                "{% endpartialdef %}\n"
    16 +                "{% endverbatim %}\n"
    17                  "{% partialdef syntax_error_partial %}\n"
    18                  "    {% if user %}\n"
    19                  "        <p>User: {{ user.name }}</p>\n"
    20 @@ -506,6 +511,7 @@ class PartialTagTests(SimpleTestCase):
    21              self.assertIn("endpartialdef", exc_debug["during"])
    22              self.assertEqual(exc_debug["name"], "partial_with_syntax_error")
    23              self.assertIn("endif", exc_debug["message"].lower())
    24 +            self.assertNotIn("verbatim", exc_debug["source_lines"][0][1])
    25  
    26      @setup(
    27          {
     3{{{#!py
     4    @setup(
     5        {
     6            "partial_embedded_in_verbatim": (
     7                "{% verbatim %}\n"
     8                "{% partialdef testing-name %}\n"
     9                "{% endverbatim %}\n"
     10                "{% partialdef testing-name %}\n"
     11                "<p>Content</p>\n"
     12                "{% endpartialdef %}\n"
     13            ),
     14        },
     15        test_once=True,
     16    )
     17    def test_partial_template_embedded_in_verbatim(self):
     18        template = self.engine.get_template("partial_embedded_in_verbatim")
     19        partial_template = template.extra_data["partials"]["testing-name"]
     20        self.assertIn("Content", partial_template.source)
    2821}}}
    2922
    3023{{{#!py
    3124======================================================================
    32 FAIL: test_partial_with_syntax_error_exception_info (template_tests.syntax_tests.test_partials.PartialTagTests.test_partial_with_syntax_error_exception_info)
     25FAIL: test_partial_template_embedded_in_verbatim (template_tests.syntax_tests.test_partials.PartialTagTests.test_partial_template_embedded_in_verbatim)
    3326----------------------------------------------------------------------
    3427Traceback (most recent call last):
     
    3629    return func(*args, **kwargs)
    3730           ^^^^^^^^^^^^^^^^^^^^^
    38   File "/Users/jwalls/django/tests/template_tests/utils.py", line 76, in inner
     31  File "/Users/jwalls/django/tests/template_tests/utils.py", line 58, in inner
    3932    func(self)
    40   File "/Users/jwalls/django/tests/template_tests/syntax_tests/test_partials.py", line 514, in test_partial_with_syntax_error_exception_info
    41     self.assertNotIn("verbatim", exc_debug["source_lines"][0][1])
    42 AssertionError: 'verbatim' unexpectedly found in '{% verbatim %}\n'
     33  File "/Users/jwalls/django/tests/template_tests/syntax_tests/test_partials.py", line 676, in test_partial_template_embedded_in_verbatim
     34    self.assertIn("Content", partial_template.source)
     35AssertionError: 'Content' not found in ''
    4336}}}
    4437----
Back to Top