[Django] #31073: SplitArrayField with BooleanField always has widgets checked after first True value

20 views
Skip to first unread message

Django

unread,
Dec 7, 2019, 7:29:25 PM12/7/19
to django-...@googlegroups.com
#31073: SplitArrayField with BooleanField always has widgets checked after first
True value
-------------------------------------+-------------------------------------
Reporter: Peter | Owner: (none)
Andersen |
Type: Bug | Status: new
Component: | Version: 2.2
contrib.postgres | Keywords: SplitArrayField
Severity: Normal | BooleanField ChecboxInput
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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

--
Ticket URL: <https://code.djangoproject.com/ticket/31073>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 7, 2019, 7:29:56 PM12/7/19
to django-...@googlegroups.com
#31073: SplitArrayField with BooleanField always has widgets checked after first
True value
-------------------------------------+-------------------------------------
Reporter: Peter Andersen | Owner: (none)
Type: Bug | Status: new
Component: contrib.postgres | Version: 2.2
Severity: Normal | Resolution:
Keywords: SplitArrayField | Triage Stage:
BooleanField ChecboxInput | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Peter Andersen:

Old description:

> 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

New description:

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

--

--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:1>

Django

unread,
Dec 7, 2019, 8:01:04 PM12/7/19
to django-...@googlegroups.com
#31073: SplitArrayField with BooleanField always has widgets checked after first
True value
-------------------------------------+-------------------------------------
Reporter: Peter Andersen | Owner: (none)
Type: Bug | Status: new

Component: contrib.postgres | Version: 2.2
Severity: Normal | Resolution:
Keywords: SplitArrayField | Triage Stage:
BooleanField ChecboxInput | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Peter Andersen):

* Attachment "dont_modify_final_attrs.diff" added.

Django

unread,
Dec 7, 2019, 8:02:33 PM12/7/19
to django-...@googlegroups.com
#31073: SplitArrayField with BooleanField always has widgets checked after first
True value
-------------------------------------+-------------------------------------
Reporter: Peter Andersen | Owner: (none)
Type: Bug | Status: new

Component: contrib.postgres | Version: 2.2
Severity: Normal | Resolution:
Keywords: SplitArrayField | Triage Stage:
BooleanField ChecboxInput | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Peter Andersen):

* has_patch: 0 => 1
* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:2>

Django

unread,
Dec 7, 2019, 8:44:40 PM12/7/19
to django-...@googlegroups.com
#31073: SplitArrayField with BooleanField always has widgets checked after first
True value
-------------------------------------+-------------------------------------
Reporter: Peter Andersen | Owner: (none)
Type: Bug | Status: new

Component: contrib.postgres | Version: 2.2
Severity: Normal | Resolution:
Keywords: SplitArrayField | Triage Stage:
BooleanField ChecboxInput | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Peter Andersen):

Changes available here: https://github.com/django/django/pull/12193

--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:3>

Django

unread,
Dec 7, 2019, 10:27:23 PM12/7/19
to django-...@googlegroups.com
#31073: SplitArrayField with BooleanField always has widgets checked after first
True value
-------------------------------------+-------------------------------------
Reporter: Peter Andersen | Owner: (none)
Type: Bug | Status: new

Component: contrib.postgres | Version: 2.2
Severity: Normal | Resolution:
Keywords: SplitArrayField | Triage Stage:
BooleanField ChecboxInput | Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Peter Andersen):

* needs_tests: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:4>

Django

unread,
Dec 9, 2019, 2:57:04 AM12/9/19
to django-...@googlegroups.com
#31073: SplitArrayField with BooleanField always has widgets checked after the
first True value.
-------------------------------------+-------------------------------------
Reporter: Peter Andersen | Owner: Peter
| Andersen
Type: Bug | Status: assigned
Component: contrib.postgres | Version: 3.0
Severity: Normal | Resolution:
Keywords: SplitArrayField | Triage Stage: Accepted
BooleanField ChecboxInput |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: new => assigned
* owner: (none) => Peter Andersen
* version: 2.2 => 3.0
* stage: Unreviewed => Accepted


Comment:

Thanks for the report.

--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:5>

Django

unread,
Dec 9, 2019, 3:40:07 AM12/9/19
to django-...@googlegroups.com
#31073: SplitArrayField with BooleanField always has widgets checked after the
first True value.
-------------------------------------+-------------------------------------
Reporter: Peter Andersen | Owner: Peter
| Andersen
Type: Bug | Status: assigned
Component: Forms | Version: 3.0

Severity: Normal | Resolution:
Keywords: SplitArrayField | Triage Stage: Accepted
BooleanField ChecboxInput |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* component: contrib.postgres => Forms


--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:6>

Django

unread,
Dec 9, 2019, 3:53:38 AM12/9/19
to django-...@googlegroups.com
#31073: SplitArrayField with BooleanField always has widgets checked after the
first True value.
-------------------------------------+-------------------------------------
Reporter: Peter Andersen | Owner: Peter
| Andersen
Type: Bug | Status: assigned
Component: Forms | Version: 3.0
Severity: Normal | Resolution:
Keywords: SplitArrayField | Triage Stage: Accepted
BooleanField ChecboxInput |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:7>

Django

unread,
Dec 9, 2019, 12:00:56 PM12/9/19
to django-...@googlegroups.com
#31073: SplitArrayField with BooleanField always has widgets checked after the
first True value.
-------------------------------------+-------------------------------------
Reporter: Peter Andersen | Owner: Peter
| Andersen
Type: Bug | Status: assigned
Component: Forms | Version: 3.0
Severity: Normal | Resolution:
Keywords: SplitArrayField | Triage Stage: Accepted
BooleanField ChecboxInput |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Peter Andersen):

* needs_better_patch: 1 => 0


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:8>

Django

unread,
Dec 10, 2019, 6:51:14 AM12/10/19
to django-...@googlegroups.com
#31073: SplitArrayField with BooleanField always has widgets checked after the
first True value.
-------------------------------------+-------------------------------------
Reporter: Peter Andersen | Owner: Peter
| Andersen
Type: Bug | Status: closed
Component: Forms | Version: 3.0
Severity: Normal | Resolution: fixed

Keywords: SplitArrayField | Triage Stage: Accepted
BooleanField ChecboxInput |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"02eff7ef60466da108b1a33f1e4dc01eec45c99d" 02eff7ef]:
{{{
#!CommitTicketReference repository=""
revision="02eff7ef60466da108b1a33f1e4dc01eec45c99d"
Fixed #31073 -- Prevented CheckboxInput.get_context() from mutating attrs.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:9>

Django

unread,
Dec 10, 2019, 7:33:36 AM12/10/19
to django-...@googlegroups.com
#31073: SplitArrayField with BooleanField always has widgets checked after the
first True value.
-------------------------------------+-------------------------------------
Reporter: Peter Andersen | Owner: Peter
| Andersen
Type: Bug | Status: closed
Component: Forms | Version: 3.0
Severity: Normal | Resolution: fixed
Keywords: SplitArrayField | Triage Stage: Accepted
BooleanField ChecboxInput |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:10>

Django

unread,
Dec 10, 2019, 7:50:48 AM12/10/19
to django-...@googlegroups.com
#31073: SplitArrayField with BooleanField always has widgets checked after the
first True value.
-------------------------------------+-------------------------------------
Reporter: Peter Andersen | Owner: Peter
| Andersen
Type: Bug | Status: closed
Component: Forms | Version: 3.0
Severity: Normal | Resolution: fixed
Keywords: SplitArrayField | Triage Stage: Accepted
BooleanField ChecboxInput |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (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).

--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:11>

Django

unread,
Dec 10, 2019, 11:29:33 AM12/10/19
to django-...@googlegroups.com
#31073: SplitArrayField with BooleanField always has widgets checked after the
first True value.
-------------------------------------+-------------------------------------
Reporter: Peter Andersen | Owner: Peter
| Andersen
Type: Bug | Status: closed
Component: Forms | Version: 3.0
Severity: Normal | Resolution: fixed
Keywords: SplitArrayField | Triage Stage: Accepted
BooleanField ChecboxInput |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Peter Andersen):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:12>

Django

unread,
Dec 10, 2019, 4:04:35 PM12/10/19
to django-...@googlegroups.com
#31073: SplitArrayField with BooleanField always has widgets checked after the
first True value.
-------------------------------------+-------------------------------------
Reporter: Peter Andersen | Owner: Peter
| Andersen
Type: Bug | Status: closed
Component: Forms | Version: 3.0
Severity: Normal | Resolution: fixed
Keywords: SplitArrayField | Triage Stage: Accepted
BooleanField ChecboxInput |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by felixxm):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:13>

Django

unread,
Dec 10, 2019, 4:09:49 PM12/10/19
to django-...@googlegroups.com
#31073: SplitArrayField with BooleanField always has widgets checked after the
first True value.
-------------------------------------+-------------------------------------
Reporter: Peter Andersen | Owner: Peter
| Andersen
Type: Bug | Status: closed
Component: Forms | Version: 3.0
Severity: Normal | Resolution: fixed
Keywords: SplitArrayField | Triage Stage: Accepted
BooleanField ChecboxInput |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Peter Andersen):

Thanks for letting me know

--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:14>

Django

unread,
Dec 11, 2019, 3:39:54 AM12/11/19
to django-...@googlegroups.com
#31073: SplitArrayField with BooleanField always has widgets checked after the
first True value.
-------------------------------------+-------------------------------------
Reporter: Peter Andersen | Owner: Peter
| Andersen
Type: Bug | Status: closed
Component: Forms | Version: 3.0
Severity: Normal | Resolution: fixed
Keywords: SplitArrayField | Triage Stage: Accepted
BooleanField ChecboxInput |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"74e14541137d444b01fa947d7408f9d4a049ad9d" 74e14541]:
{{{
#!CommitTicketReference repository=""
revision="74e14541137d444b01fa947d7408f9d4a049ad9d"
[3.0.x] Fixed #31073 -- Prevented CheckboxInput.get_context() from
mutating attrs.

Backport of 02eff7ef60466da108b1a33f1e4dc01eec45c99d from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:15>

Django

unread,
Dec 11, 2019, 3:42:31 AM12/11/19
to django-...@googlegroups.com
#31073: SplitArrayField with BooleanField always has widgets checked after the
first True value.
-------------------------------------+-------------------------------------
Reporter: Peter Andersen | Owner: Peter
| Andersen
Type: Bug | Status: closed
Component: Forms | Version: 3.0
Severity: Normal | Resolution: fixed
Keywords: SplitArrayField | Triage Stage: Accepted
BooleanField ChecboxInput |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"f33be1e8ae2efbca5f209e2365fa35c2aaee340c" f33be1e8]:
{{{
#!CommitTicketReference repository=""
revision="f33be1e8ae2efbca5f209e2365fa35c2aaee340c"
[2.2.x] Fixed #31073 -- Prevented CheckboxInput.get_context() from
mutating attrs.

Backport of 02eff7ef60466da108b1a33f1e4dc01eec45c99d from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:16>

Django

unread,
Dec 11, 2019, 3:49:39 AM12/11/19
to django-...@googlegroups.com
#31073: SplitArrayField with BooleanField always has widgets checked after the
first True value.
-------------------------------------+-------------------------------------
Reporter: Peter Andersen | Owner: Peter
| Andersen
Type: Bug | Status: closed
Component: Forms | Version: 3.0
Severity: Normal | Resolution: fixed
Keywords: SplitArrayField | Triage Stage: Accepted
BooleanField ChecboxInput |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"e8fdf00cc2acdcc992fd9621230e927594dc5d4f" e8fdf00c]:
{{{
#!CommitTicketReference repository=""
revision="e8fdf00cc2acdcc992fd9621230e927594dc5d4f"
[1.11.x] Fixed #31073 -- Prevented CheckboxInput.get_context() from
mutating attrs.

Backport of 02eff7ef60466da108b1a33f1e4dc01eec45c99d from master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:17>

Django

unread,
Dec 11, 2019, 4:08:24 AM12/11/19
to django-...@googlegroups.com
#31073: SplitArrayField with BooleanField always has widgets checked after the
first True value.
-------------------------------------+-------------------------------------
Reporter: Peter Andersen | Owner: Peter
| Andersen
Type: Bug | Status: closed
Component: Forms | Version: 3.0
Severity: Normal | Resolution: fixed
Keywords: SplitArrayField | Triage Stage: Accepted
BooleanField ChecboxInput |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by GitHub <noreply@…>):

In [changeset:"ec12c37384798093e359971c8980fe0c68d555bc" ec12c373]:
{{{
#!CommitTicketReference repository=""
revision="ec12c37384798093e359971c8980fe0c68d555bc"
Refs #31073 -- Added release notes for
02eff7ef60466da108b1a33f1e4dc01eec45c99d.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:18>

Django

unread,
Dec 11, 2019, 4:09:31 AM12/11/19
to django-...@googlegroups.com
#31073: SplitArrayField with BooleanField always has widgets checked after the
first True value.
-------------------------------------+-------------------------------------
Reporter: Peter Andersen | Owner: Peter
| Andersen
Type: Bug | Status: closed
Component: Forms | Version: 3.0
Severity: Normal | Resolution: fixed
Keywords: SplitArrayField | Triage Stage: Accepted
BooleanField ChecboxInput |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"f4baf2fdf67136fb24fa88faa0cb3efb31b8125f" f4baf2f]:
{{{
#!CommitTicketReference repository=""
revision="f4baf2fdf67136fb24fa88faa0cb3efb31b8125f"
[3.0.x] Refs #31073 -- Added release notes for
02eff7ef60466da108b1a33f1e4dc01eec45c99d.

Backport of ec12c37384798093e359971c8980fe0c68d555bc from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:19>

Django

unread,
Dec 11, 2019, 4:13:41 AM12/11/19
to django-...@googlegroups.com
#31073: SplitArrayField with BooleanField always has widgets checked after the
first True value.
-------------------------------------+-------------------------------------
Reporter: Peter Andersen | Owner: Peter
| Andersen
Type: Bug | Status: closed
Component: Forms | Version: 3.0
Severity: Normal | Resolution: fixed
Keywords: SplitArrayField | Triage Stage: Accepted
BooleanField ChecboxInput |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"86befcc172c23170a720b3e0c06db51a99b3da59" 86befcc]:
{{{
#!CommitTicketReference repository=""
revision="86befcc172c23170a720b3e0c06db51a99b3da59"
[2.2.x] Refs #31073 -- Added release notes for
02eff7ef60466da108b1a33f1e4dc01eec45c99d.

Backport of ec12c37384798093e359971c8980fe0c68d555bc from master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:20>

Django

unread,
Dec 11, 2019, 4:18:29 AM12/11/19
to django-...@googlegroups.com
#31073: SplitArrayField with BooleanField always has widgets checked after the
first True value.
-------------------------------------+-------------------------------------
Reporter: Peter Andersen | Owner: Peter
| Andersen
Type: Bug | Status: closed
Component: Forms | Version: 3.0
Severity: Normal | Resolution: fixed
Keywords: SplitArrayField | Triage Stage: Accepted
BooleanField ChecboxInput |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"a2355740ed76ca9461b34d65beb450c0156f3224" a2355740]:
{{{
#!CommitTicketReference repository=""
revision="a2355740ed76ca9461b34d65beb450c0156f3224"
[1.11.x] Refs #31073 -- Added release notes for
02eff7ef60466da108b1a33f1e4dc01eec45c99d.

Backport of ec12c37384798093e359971c8980fe0c68d555bc from master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:21>

Reply all
Reply to author
Forward
0 new messages