Opened 10 years ago
Closed 10 years ago
#23834 closed Bug (fixed)
ArrayField default is an empty string and not None
Reported by: | ddaan | Owned by: | |
---|---|---|---|
Component: | contrib.postgres | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Considering this class (from tests.postgres_tests.models):
class NullableIntegerArrayModel(models.Model): field = ArrayField(models.IntegerField(), blank=True, null=True)
When I save it directly after initialization it will result in an error
django.db.utils.DataError: array value must start with "{" or dimension information
LINE 1: ...ests_nullableintegerarraymodel" ("field") VALUES () RETURN...
This test will reproduce the error
def test_default_null(self): instance = NullableIntegerArrayModel() instance.save() loaded = NullableIntegerArrayModel.objects.get(pk=instance.pk) self.assertEqual(loaded.field, None) self.assertEqual(instance.field, loaded.field)
Change History (5)
comment:1 by , 10 years ago
Version: | 1.7 → master |
---|
comment:2 by , 10 years ago
Description: | modified (diff) |
---|
comment:3 by , 10 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:5 by , 10 years ago
Owner: | set to |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Only the first two lines of the test are needed (it's the call to .save()) that crashes.
The exact same thing happens with a normal IntegerArrayModel, it's not specific to the Nullable one.
get_default() in ArrayField defaults to returning , it seems that should be None or [] depending on the value of self.null.