From 84633905273fc916e3d17883810d9969c03f73c2 Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Fri, 1 Nov 2019 12:08:03 +0100 Subject: [PATCH] Refs #27808 -- Added test for saving nested ArrayField with nullable base field. --- .../postgres_tests/migrations/0002_create_test_models.py | 4 ++++ tests/postgres_tests/models.py | 1 + tests/postgres_tests/test_array.py | 9 +++++++++ 3 files changed, 14 insertions(+) diff --git a/tests/postgres_tests/migrations/0002_create_test_models.py b/tests/postgres_tests/migrations/0002_create_test_models.py index 1b9c45881fa..0e36cd1256b 100644 --- a/tests/postgres_tests/migrations/0002_create_test_models.py +++ b/tests/postgres_tests/migrations/0002_create_test_models.py @@ -96,6 +96,10 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('field', ArrayField(models.IntegerField(), size=None, null=True, blank=True)), + ( + 'field_nested', + ArrayField(ArrayField(models.IntegerField(), size=None, null=True), size=None, null=True), + ), ], options={ 'required_db_vendor': 'postgresql', diff --git a/tests/postgres_tests/models.py b/tests/postgres_tests/models.py index 5b2f41160a1..2cf47b88c77 100644 --- a/tests/postgres_tests/models.py +++ b/tests/postgres_tests/models.py @@ -46,6 +46,7 @@ class IntegerArrayModel(PostgreSQLModel): class NullableIntegerArrayModel(PostgreSQLModel): field = ArrayField(models.IntegerField(), blank=True, null=True) + field_nested = ArrayField(ArrayField(models.IntegerField(null=True)), null=True) class CharArrayModel(PostgreSQLModel): diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py index 708852f71cd..379a1e9bba7 100644 --- a/tests/postgres_tests/test_array.py +++ b/tests/postgres_tests/test_array.py @@ -31,6 +31,7 @@ try: from django.contrib.postgres.forms import ( SimpleArrayField, SplitArrayField, SplitArrayWidget, ) + from django.db.backends.postgresql.base import PSYCOPG2_VERSION from psycopg2.extras import NumericRange except ImportError: pass @@ -140,6 +141,14 @@ class TestSaveLoad(PostgreSQLTestCase): self.assertEqual(field.model, IntegerArrayModel) self.assertEqual(field.base_field.model, IntegerArrayModel) + def test_nested_nullable_base_field(self): + if PSYCOPG2_VERSION < (2, 7, 5): + self.skipTest('See https://github.com/psycopg/psycopg2/issues/325') + instance = NullableIntegerArrayModel.objects.create( + field_nested=[[None, None], [None, None]], + ) + self.assertEqual(instance.field_nested, [[None, None], [None, None]]) + class TestQuerying(PostgreSQLTestCase):