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.
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>
* Attachment "dont_modify_final_attrs.diff" added.
* has_patch: 0 => 1
* needs_tests: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:2>
Comment (by Peter Andersen):
Changes available here: https://github.com/django/django/pull/12193
--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:3>
* needs_tests: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:4>
* 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>
* component: contrib.postgres => Forms
--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:6>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:7>
* 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>
* 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>
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>
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>
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>
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>
Comment (by Peter Andersen):
Thanks for letting me know
--
Ticket URL: <https://code.djangoproject.com/ticket/31073#comment:14>
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>
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>
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>
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>
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>
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>
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>