Opened 5 years ago

Closed 5 years ago

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

Download all attachments as: .zip

Change History (22)

comment:1 by Peter Andersen, 5 years ago

Description: modified (diff)

by Peter Andersen, 5 years ago

comment:2 by Peter Andersen, 5 years ago

Has patch: set
Needs tests: set

comment:3 by Peter Andersen, 5 years ago

comment:4 by Peter Andersen, 5 years ago

Needs tests: unset

comment:5 by Mariusz Felisiak, 5 years ago

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 5 years ago by Mariusz Felisiak (previous) (diff)

comment:6 by Mariusz Felisiak, 5 years ago

Component: contrib.postgresForms

comment:7 by Mariusz Felisiak, 5 years ago

Patch needs improvement: set

comment:8 by Peter Andersen, 5 years ago

Patch needs improvement: unset

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

comment:9 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 02eff7ef:

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

comment:10 by Claude Paroz, 5 years ago

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

comment:11 by Mariusz Felisiak, 5 years ago

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

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

comment:13 by Mariusz Felisiak, 5 years ago

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

comment:14 by Peter Andersen, 5 years ago

Thanks for letting me know

comment:15 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In 74e14541:

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

Backport of 02eff7ef60466da108b1a33f1e4dc01eec45c99d from master

comment:16 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In f33be1e8:

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

Backport of 02eff7ef60466da108b1a33f1e4dc01eec45c99d from master

comment:17 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In e8fdf00c:

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

Backport of 02eff7ef60466da108b1a33f1e4dc01eec45c99d from master.

comment:18 by GitHub <noreply@…>, 5 years ago

In ec12c373:

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

comment:19 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In f4baf2f:

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

Backport of ec12c37384798093e359971c8980fe0c68d555bc from master

comment:20 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In 86befcc:

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

Backport of ec12c37384798093e359971c8980fe0c68d555bc from master.

comment:21 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

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