Opened 15 months ago

Last modified 14 months ago

#36559 closed Bug

partialdef tag embedded in verbatim tag is treated as the source property for that named partial — at Version 4

Reported by: Jacob Walls Owned by: Farhan Ali
Component: Template system Version: dev
Severity: Release blocker Keywords: partials
Cc: Carlton Gibson, Farhan Ali Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Jacob Walls)

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

    @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)
======================================================================
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.

Change History (4)

comment:1 by Jacob Walls, 15 months ago

Description: modified (diff)
Summary: partialdef tag embedded in verbatim tag is treated as the source attribute for that named partial → partialdef tag embedded in verbatim tag is treated as the source property for that named partial

comment:2 by Natalia Bidart, 14 months ago

Cc: Carlton Gibson Farhan Ali added
Keywords: partials added
Triage Stage: Unreviewed → Accepted

Thank you Jacob, I agree that we should treat as release blocker.

comment:3 by Farhan Ali, 14 months ago

Owner: set to Farhan Ali
Status: new → assigned

comment:4 by Jacob Walls, 14 months ago

Description: modified (diff)

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

Note: See TracTickets for help on using tickets.
Back to Top