Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#28577 closed New feature (fixed)

Create system checks for mutable defaults on ArrayField and JSONField

Reported by: Flávio Juvenal Owned by: Flávio Juvenal
Component: Core (System checks) Version: dev
Severity: Normal Keywords: check
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

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

Change History (11)

comment:1 by Flávio Juvenal, 7 years ago

Owner: changed from nobody to Flávio Juvenal
Status: newassigned

comment:2 by Flávio Juvenal, 7 years ago

UI/UX: unset

comment:3 by Flávio Juvenal, 7 years ago

Version: 1.11master

comment:4 by Flávio Juvenal, 7 years ago

Summary: Create system check for ArrayField(default=[]) (ArrayField with non-callable mutable default)Create system checks for mutable defaults on ArrayField and JSONField

comment:5 by Curtis Maloney, 7 years ago

Triage Stage: UnreviewedReady for checkin

comment:6 by Tim Graham, 7 years ago

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

comment:8 by Flávio Juvenal, 7 years ago

comment:9 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: assignedclosed

In f6e1789:

Fixed #28577 -- Added checks for ArrayField and JSONField to prevent mutable defaults.

comment:10 by Tim Graham, 6 years ago

PR for HStoreField (as suggested in #28406).

comment:11 by GitHub <noreply@…>, 6 years ago

In 4f7467b6:

Refs #28577 -- Added check for HStoreField to prevent mutable default.

Note: See TracTickets for help on using tickets.
Back to Top