Opened 10 years ago

Closed 8 years ago

#22962 closed Bug (fixed)

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

Reported by: Matthew Schinckel Owned by: Marc Tamlyn <marc.tamlyn@…>
Component: contrib.postgres Version: dev
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 (11)

comment:1 by Matthew Schinckel, 10 years ago

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

comment:2 by Matthew Schinckel, 10 years ago

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

if value == '[]':

value = '{}'

makes it work as expected.

Version 0, edited 10 years ago by Matthew Schinckel (next)

comment:3 by Tim Graham, 10 years ago

Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:4 by Marc Tamlyn, 10 years ago

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 by Marc Tamlyn, 10 years ago

Has patch: set

comment:6 by Marc Tamlyn <marc.tamlyn@…>, 10 years ago

Owner: set to Marc Tamlyn <marc.tamlyn@…>
Resolution: fixed
Status: newclosed

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 by Markus Holtermann <info@…>, 10 years ago

In b06935a486e633e9732bce2bc5f796eb437b2531:

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

comment:8 by Markus Holtermann <info@…>, 10 years ago

In 45d93baf518218c39b70fbc1eb35e9b53f66cf98:

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

Backport of b06935a486e633e9732bce2bc5f796eb437b2531 from master

comment:9 by Doug Whiteley, 8 years ago

Resolution: fixed
Status: closednew

This is happening again.

django.db.utils.DataError: malformed array literal: ""
DETAIL:  Array value must start with "{" or dimension information.

Checked on 1.10 and 1.11rc1.

comment:10 by Matthew Schinckel, 8 years ago

I'm not sure it's exactly the same issue: it's a different error message, for one.

comment:11 by Doug Whiteley, 8 years ago

Resolution: fixed
Status: newclosed

Reopened in error

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