#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 <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/01070198bd1fd921-0e7a9f61-aae5-4278-b9e6-2b30daae1609-000000%40eu-central-1.amazonses.com.

Reply via email to