From a7c58eaca45ede76f94d2859877c7f42b28c48da Mon Sep 17 00:00:00 2001 From: Daan Vielen Date: Sat, 15 Nov 2014 14:04:34 +0000 Subject: [PATCH] added test and fix to check for default null on ArrayField --- django/contrib/postgres/fields/array.py | 2 +- tests/postgres_tests/test_array.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/django/contrib/postgres/fields/array.py b/django/contrib/postgres/fields/array.py index ab57ccb110..87c2de43b4 100644 --- a/django/contrib/postgres/fields/array.py +++ b/django/contrib/postgres/fields/array.py @@ -100,7 +100,7 @@ class ArrayField(Field): if callable(self.default): return self.default() return self.default - return '' + return None def value_to_string(self, obj): values = [] diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py index 33cf837dd4..68378483ec 100644 --- a/tests/postgres_tests/test_array.py +++ b/tests/postgres_tests/test_array.py @@ -48,6 +48,13 @@ class TestSaveLoad(TestCase): loaded = IntegerArrayModel.objects.get() self.assertEqual(loaded.field, [1]) + 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) + def test_null_handling(self): instance = NullableIntegerArrayModel(field=None) instance.save()