Opened 11 months ago

Closed 10 months ago

Last modified 4 months 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: master
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 Changed 11 months ago by Flávio Juvenal

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

comment:2 Changed 11 months ago by Flávio Juvenal

UI/UX: unset

comment:3 Changed 11 months ago by Flávio Juvenal

Version: 1.11master

comment:4 Changed 11 months ago by Flávio Juvenal

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 Changed 11 months ago by Curtis Maloney

Triage Stage: UnreviewedReady for checkin

comment:6 Changed 10 months ago by Tim Graham

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

comment:8 Changed 10 months ago by Flávio Juvenal

comment:9 Changed 10 months ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In f6e1789:

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

comment:10 Changed 4 months ago by Tim Graham

PR for HStoreField (as suggested in #28406).

comment:11 Changed 4 months ago by GitHub <noreply@…>

In 4f7467b6:

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

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