Opened 2 months ago

Closed 4 weeks 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 (9)

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

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

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

UI/UX: unset

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

Version: 1.11master

comment:4 Changed 2 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 2 months ago by Curtis Maloney

Triage Stage: UnreviewedReady for checkin

comment:6 Changed 6 weeks ago by Tim Graham

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

comment:8 Changed 5 weeks ago by Flávio Juvenal

comment:9 Changed 4 weeks ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In f6e1789:

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

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