Opened 13 months ago

Closed 12 months ago

Last modified 6 months ago

#22962 closed Bug (fixed)

Default of [] for postgres array field results in migration application failure.

Reported by: schinckel Owned by: Marc Tamlyn <marc.tamlyn@…>
Component: contrib.postgres Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Creating an ArrayField with a default of [] results in an error when attempting to run the migration:

django.db.utils.DataError: missing dimension value

It seems that the literal [] is being sent through to the database, rather than the postgres-speak for an empty array: '{}'

It's the same issue as seen elsewhere on the internet when dealing with postgres arrays:

https://github.com/ecometrica/django-dbarray/issues/2

Change History (8)

comment:1 Changed 13 months ago by schinckel

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Oh, it was an undimensioned array: not sure if that's important.

comment:2 Changed 13 months ago by schinckel

In ArrayField.get_prep_value(self,value), adding:

    if value == '[]':
        value = '{}'

makes it work as expected.

Last edited 13 months ago by schinckel (previous) (diff)

comment:3 Changed 13 months ago by timo

  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Bug

comment:4 Changed 13 months ago by mjtamlyn

PR: https://github.com/django/django/pull/2925

Not sure why I am getting a string from the migration runner, seems a little strange. Nonetheless it works now.

comment:5 Changed 13 months ago by mjtamlyn

  • Has patch set

comment:6 Changed 12 months ago by Marc Tamlyn <marc.tamlyn@…>

  • Owner set to Marc Tamlyn <marc.tamlyn@…>
  • Resolution set to fixed
  • Status changed from new to closed

In ef9f109013adc6e140c1a71d874aa88e893657b7:

Fixed #22962 -- Default values for ArrayField with migrations.

Fields normally try to force the default value to a string. As
translatable strings are not valid default values for ArrayField, we can
remove this behaviour which was causing issues with some migrations.

Thanks to @schinckel for the report.

comment:7 Changed 6 months ago by Markus Holtermann <info@…>

In b06935a486e633e9732bce2bc5f796eb437b2531:

Refs #22962 -- Made test case use non-conflicting table names

comment:8 Changed 6 months ago by Markus Holtermann <info@…>

In 45d93baf518218c39b70fbc1eb35e9b53f66cf98:

[1.8.x] Refs #22962 -- Made test case use non-conflicting table names

Backport of b06935a486e633e9732bce2bc5f796eb437b2531 from master

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