Opened 8 months ago

Closed 8 months ago

Last modified 8 months ago

#31073 closed Bug (fixed)

SplitArrayField with BooleanField always has widgets checked after the first True value.

Reported by: Peter Andersen Owned by: Peter Andersen
Component: Forms Version: 3.0
Severity: Normal Keywords: SplitArrayField BooleanField ChecboxInput
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Peter Andersen)

When providing a SplitArrayField BooleanField with preexisting data, the final_attrs dict is updated to include 'checked': True after the for loop has reached the first True value in the initial data array. Once this occurs every widget initialized after that defaults to checked even though the backing data may be False. This is caused by the CheckboxInput widget's get_context() modifying the attrs dict passed into it. This is the only widget that modifies the attrs dict passed into its get_context().

CheckboxInput setting attrs['checked'] to True: https://github.com/django/django/blob/master/django/forms/widgets.py#L527

Attachments (1)

dont_modify_final_attrs.diff (661 bytes) - added by Peter Andersen 8 months ago.

Download all attachments as: .zip

Change History (22)

comment:1 Changed 8 months ago by Peter Andersen

Description: modified (diff)

Changed 8 months ago by Peter Andersen

comment:2 Changed 8 months ago by Peter Andersen

Has patch: set
Needs tests: set

comment:3 Changed 8 months ago by Peter Andersen

comment:4 Changed 8 months ago by Peter Andersen

Needs tests: unset

comment:5 Changed 8 months ago by felixxm

Owner: set to Peter Andersen
Status: newassigned
Summary: SplitArrayField with BooleanField always has widgets checked after first True valueSplitArrayField with BooleanField always has widgets checked after the first True value.
Triage Stage: UnreviewedAccepted
Version: 2.23.0

Thanks for the report.

Version 0, edited 8 months ago by felixxm (next)

comment:6 Changed 8 months ago by felixxm

Component: contrib.postgresForms

comment:7 Changed 8 months ago by felixxm

Patch needs improvement: set

comment:8 Changed 8 months ago by Peter Andersen

Patch needs improvement: unset

Suggested changes applied to the PR: https://github.com/django/django/pull/12193

comment:9 Changed 8 months ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In 02eff7ef:

Fixed #31073 -- Prevented CheckboxInput.get_context() from mutating attrs.

comment:10 Changed 8 months ago by Claude Paroz

Isn't this a possible data corruption issue worth to be backported?

comment:11 Changed 8 months ago by felixxm

It seems that it's a regression in b52c73008a9d67e9ddbb841872dc15cdd3d6ee01. I agree that this qualifies for a backport as a data loss bug to Django 3.0 (maybe also to 2.2 and 1.11).

comment:12 Changed 8 months ago by Peter Andersen

I'll make some PRs to backport the fix to the various active releases.

comment:13 Changed 8 months ago by felixxm

Peter Andersen, you don't need to create fixes for other versions, commiters will backport fix (if necessary).

comment:14 Changed 8 months ago by Peter Andersen

Thanks for letting me know

comment:15 Changed 8 months ago by Mariusz Felisiak <felisiak.mariusz@…>

In 74e14541:

[3.0.x] Fixed #31073 -- Prevented CheckboxInput.get_context() from mutating attrs.

Backport of 02eff7ef60466da108b1a33f1e4dc01eec45c99d from master

comment:16 Changed 8 months ago by Mariusz Felisiak <felisiak.mariusz@…>

In f33be1e8:

[2.2.x] Fixed #31073 -- Prevented CheckboxInput.get_context() from mutating attrs.

Backport of 02eff7ef60466da108b1a33f1e4dc01eec45c99d from master

comment:17 Changed 8 months ago by Mariusz Felisiak <felisiak.mariusz@…>

In e8fdf00c:

[1.11.x] Fixed #31073 -- Prevented CheckboxInput.get_context() from mutating attrs.

Backport of 02eff7ef60466da108b1a33f1e4dc01eec45c99d from master.

comment:18 Changed 8 months ago by GitHub <noreply@…>

In ec12c373:

Refs #31073 -- Added release notes for 02eff7ef60466da108b1a33f1e4dc01eec45c99d.

comment:19 Changed 8 months ago by Mariusz Felisiak <felisiak.mariusz@…>

In f4baf2f:

[3.0.x] Refs #31073 -- Added release notes for 02eff7ef60466da108b1a33f1e4dc01eec45c99d.

Backport of ec12c37384798093e359971c8980fe0c68d555bc from master

comment:20 Changed 8 months ago by Mariusz Felisiak <felisiak.mariusz@…>

In 86befcc:

[2.2.x] Refs #31073 -- Added release notes for 02eff7ef60466da108b1a33f1e4dc01eec45c99d.

Backport of ec12c37384798093e359971c8980fe0c68d555bc from master.

comment:21 Changed 8 months ago by Mariusz Felisiak <felisiak.mariusz@…>

In a2355740:

[1.11.x] Refs #31073 -- Added release notes for 02eff7ef60466da108b1a33f1e4dc01eec45c99d.

Backport of ec12c37384798093e359971c8980fe0c68d555bc from master.

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