Opened 3 weeks ago

Closed 3 weeks ago

Last modified 3 weeks ago

#37463 closed Bug (fixed)

legend_tag() can double-render a required_css_class (attrs mutation)

Reported by: Jacob Walls Owned by: Jacob Walls
Component: Forms Version: 6.1
Severity: Release blocker Keywords: boundfield, label, legend
Cc: Varun Kasyap Pentamaraju Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

We have a minor regression with legend_tag() from 0eec2a163a4b2ea4e82c53ae1d7b71bf43ac911d. We just need to not mutate any attrs that are passed so we don't get double-rendering in some cases:

    def test_legend_has_required_css_class_multiple_render(self):
        class SomeForm(Form):
            required_css_class = "required"
            field = CharField(max_length=10)

        f = SomeForm({"field": "test"})
        attrs = {"class": "foo"}
        self.assertHTMLEqual(
            f["field"].legend_tag(attrs=attrs),
            '<legend class="foo required">Field:</legend>',
        )
        self.assertHTMLEqual(
            f["field"].legend_tag(attrs=attrs),
            '<legend class="foo required">Field:</legend>',
        )
FAIL: test_legend_has_required_css_class_multiple_render (forms_tests.tests.test_forms.FormsTestCase.test_legend_has_required_css_class_multiple_render)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jwalls/django/tests/forms_tests/tests/test_forms.py", line 3989, in test_legend_has_required_css_class_multiple_render
    self.assertHTMLEqual(
    ~~~~~~~~~~~~~~~~~~~~^
        f["field"].legend_tag(attrs=attrs),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        '<legend class="foo required">Field:</legend>',
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
AssertionError: <legend class="foo required required">
Field:
</legend> != <legend class="foo required">
Field:
</legend>
- <legend class="foo required required">
?                    ---------

+ <legend class="foo required">
  Field:
  </legend>

Change History (6)

comment:1 by Jacob Walls, 3 weeks ago

Has patch: set

Easy picking, so only self-assigned due to the release blocker nature, given it's a few days out.

​PR

comment:2 by Sarah Boyce, 3 weeks ago

Triage Stage: Unreviewed → Accepted

Well spotted!

comment:3 by Sarah Boyce, 3 weeks ago

Triage Stage: Accepted → Ready for checkin

comment:4 by Jacob Walls <jacobtylerwalls@…>, 3 weeks ago

Resolution: → fixed
Status: assigned → closed

In 817df1c:

Fixed #37463 -- Fixed attrs mutation in legend_tag().

Regression in 0eec2a163a4b2ea4e82c53ae1d7b71bf43ac911d.

comment:5 by Jacob Walls <jacobtylerwalls@…>, 3 weeks ago

In 8485c6a:

[6.1.x] Fixed #37463 -- Fixed attrs mutation in legend_tag().

Regression in 0eec2a163a4b2ea4e82c53ae1d7b71bf43ac911d.

Backport of 817df1c4d6d38f416460d7d9354d7deab9d35139 from main.

in reply to:  2 comment:6 by Jacob Walls, 3 weeks ago

Replying to Sarah Boyce:

Well spotted!

All credit goes to the model that ran a scan. Unless you count spotting an actual regression amongst false positives as spotting :-)

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