Opened 4 years ago

Closed 4 years ago

Last modified 4 years 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 4 years ago.

Download all attachments as: .zip

Change History (22)

comment:1 Changed 4 years ago by Peter Andersen

Description: modified (diff)

Changed 4 years ago by Peter Andersen

comment:2 Changed 4 years ago by Peter Andersen

Has patch: set
Needs tests: set

comment:3 Changed 4 years ago by Peter Andersen

comment:4 Changed 4 years ago by Peter Andersen

Needs tests: unset

comment:5 Changed 4 years ago by Mariusz Felisiak

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.

Reproduced at 5708327c3769262b845730996ca2784245ada4d1.

Last edited 4 years ago by Mariusz Felisiak (previous) (diff)

comment:6 Changed 4 years ago by Mariusz Felisiak

Component: contrib.postgresForms

comment:7 Changed 4 years ago by Mariusz Felisiak

Patch needs improvement: set

comment:8 Changed 4 years ago by Peter Andersen

Patch needs improvement: unset

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

comment:9 Changed 4 years ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In 02eff7ef:

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

comment:10 Changed 4 years ago by Claude Paroz

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

comment:11 Changed 4 years ago by Mariusz Felisiak

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 4 years ago by Peter Andersen

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

comment:13 Changed 4 years ago by Mariusz Felisiak

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

comment:14 Changed 4 years ago by Peter Andersen

Thanks for letting me know

comment:15 Changed 4 years 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 4 years 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 4 years 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 4 years ago by GitHub <noreply@…>

In ec12c373:

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

comment:19 Changed 4 years 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 4 years 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 4 years 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