Opened 10 years ago
Last modified 10 years ago
#23834 closed Bug
ArrayField default is an empty string and not None — at Initial Version
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
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)