[Django] #28577: Create system check for ArrayField(default=[]) (ArrayField with non-callable mutable default)

11 views
Skip to first unread message

Django

unread,
Sep 8, 2017, 5:50:04 PM9/8/17
to django-...@googlegroups.com
#28577: Create system check for ArrayField(default=[]) (ArrayField with non-
callable mutable default)
------------------------------------------------+------------------------
Reporter: Flávio Juvenal | Owner: nobody
Type: New feature | Status: new
Component: Core (System checks) | Version: 1.11
Severity: Normal | Keywords: check
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 1 |
------------------------------------------------+------------------------
Django docs state "Incorrectly using default=[] creates a mutable default
that is shared between all instances of ArrayField." [1].
This is a subtle bug that can be prevented with a new system check. IMO
error prevention is good UX. Django should have system checks for those
warnings in docs.
I've implemented this check: https://github.com/django/django/pull/8930

[1]
https://docs.djangoproject.com/en/1.11/ref/contrib/postgres/fields/#django.contrib.postgres.fields.ArrayField

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

Django

unread,
Sep 8, 2017, 5:51:03 PM9/8/17
to django-...@googlegroups.com
#28577: Create system check for ArrayField(default=[]) (ArrayField with non-
callable mutable default)
-------------------------------------+-------------------------------------
Reporter: Flávio Juvenal | Owner: Flávio
| Juvenal
Type: New feature | Status: assigned
Component: Core (System | Version: 1.11
checks) |
Severity: Normal | Resolution:

Keywords: check | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Flávio Juvenal):

* owner: nobody => Flávio Juvenal
* status: new => assigned


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

Django

unread,
Sep 8, 2017, 5:53:03 PM9/8/17
to django-...@googlegroups.com
#28577: Create system check for ArrayField(default=[]) (ArrayField with non-
callable mutable default)
-------------------------------------+-------------------------------------
Reporter: Flávio Juvenal | Owner: Flávio
| Juvenal
Type: New feature | Status: assigned
Component: Core (System | Version: 1.11
checks) |
Severity: Normal | Resolution:
Keywords: check | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0

-------------------------------------+-------------------------------------
Changes (by Flávio Juvenal):

* ui_ux: 1 => 0


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

Django

unread,
Sep 8, 2017, 5:58:03 PM9/8/17
to django-...@googlegroups.com
#28577: Create system check for ArrayField(default=[]) (ArrayField with non-
callable mutable default)
-------------------------------------+-------------------------------------
Reporter: Flávio Juvenal | Owner: Flávio
| Juvenal
Type: New feature | Status: assigned
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:

Keywords: check | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Flávio Juvenal):

* version: 1.11 => master


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

Django

unread,
Sep 8, 2017, 8:05:20 PM9/8/17
to django-...@googlegroups.com
#28577: Create system checks for mutable defaults on ArrayField and JSONField

-------------------------------------+-------------------------------------
Reporter: Flávio Juvenal | Owner: Flávio
| Juvenal
Type: New feature | Status: assigned
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: check | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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

Django

unread,
Sep 19, 2017, 7:06:47 PM9/19/17
to django-...@googlegroups.com
#28577: Create system checks for mutable defaults on ArrayField and JSONField
-------------------------------------+-------------------------------------
Reporter: Flávio Juvenal | Owner: Flávio
| Juvenal
Type: New feature | Status: assigned
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: check | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Curtis Maloney):

* stage: Unreviewed => Ready for checkin


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

Django

unread,
Oct 9, 2017, 5:18:23 PM10/9/17
to django-...@googlegroups.com
#28577: Create system checks for mutable defaults on ArrayField and JSONField
-------------------------------------+-------------------------------------
Reporter: Flávio Juvenal | Owner: Flávio
| Juvenal
Type: New feature | Status: assigned
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: check | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1
* stage: Ready for checkin => Accepted


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

Django

unread,
Oct 10, 2017, 2:24:31 PM10/10/17
to django-...@googlegroups.com
#28577: Create system checks for mutable defaults on ArrayField and JSONField
-------------------------------------+-------------------------------------
Reporter: Flávio Juvenal | Owner: Flávio
| Juvenal
Type: New feature | Status: assigned
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: check | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Flávio Juvenal):

PR updated: https://github.com/django/django/pull/8930

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

Django

unread,
Oct 11, 2017, 1:29:05 PM10/11/17
to django-...@googlegroups.com
#28577: Create system checks for mutable defaults on ArrayField and JSONField
-------------------------------------+-------------------------------------
Reporter: Flávio Juvenal | Owner: Flávio
| Juvenal
Type: New feature | Status: assigned
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: check | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Flávio Juvenal):

PR updated again: ​https://github.com/django/django/pull/8930

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

Django

unread,
Oct 20, 2017, 1:57:09 PM10/20/17
to django-...@googlegroups.com
#28577: Create system checks for mutable defaults on ArrayField and JSONField
-------------------------------------+-------------------------------------
Reporter: Flávio Juvenal | Owner: Flávio
| Juvenal
Type: New feature | Status: closed

Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution: fixed

Keywords: check | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"f6e1789654e82bac08cead5a2d2a9132f6403f52" f6e1789]:
{{{
#!CommitTicketReference repository=""
revision="f6e1789654e82bac08cead5a2d2a9132f6403f52"
Fixed #28577 -- Added checks for ArrayField and JSONField to prevent
mutable defaults.
}}}

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

Django

unread,
Apr 3, 2018, 9:41:41 AM4/3/18
to django-...@googlegroups.com
#28577: Create system checks for mutable defaults on ArrayField and JSONField
-------------------------------------+-------------------------------------
Reporter: Flávio Juvenal | Owner: Flávio
| Juvenal
Type: New feature | Status: closed
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution: fixed
Keywords: check | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

[https://github.com/django/django/pull/9852 PR] for `HStoreField` (as
suggested in #28406).

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

Django

unread,
Apr 3, 2018, 11:13:26 AM4/3/18
to django-...@googlegroups.com
#28577: Create system checks for mutable defaults on ArrayField and JSONField
-------------------------------------+-------------------------------------
Reporter: Flávio Juvenal | Owner: Flávio
| Juvenal
Type: New feature | Status: closed
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution: fixed
Keywords: check | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by GitHub <noreply@…>):

In [changeset:"4f7467b6905482a5d826c2815dcf8c6dd332340d" 4f7467b6]:
{{{
#!CommitTicketReference repository=""
revision="4f7467b6905482a5d826c2815dcf8c6dd332340d"
Refs #28577 -- Added check for HStoreField to prevent mutable default.
}}}

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

Reply all
Reply to author
Forward
0 new messages