From 7c50e7eeccd4b4581542547f5ddb603bbd62a725 Mon Sep 17 00:00:00 2001 From: Jernej Kos Date: Sun, 21 Dec 2014 11:21:37 +0100 Subject: [PATCH] Fixed #24034 -- Don't always overwrite deconstruct path. Made deconstruct path overwriting for ArrayField conditional, so it only occurs when the deconstructed field is an instance of ArrayField itself and not a subclass. --- django/contrib/postgres/fields/array.py | 3 ++- tests/postgres_tests/models.py | 5 +++++ tests/postgres_tests/test_array.py | 11 ++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/django/contrib/postgres/fields/array.py b/django/contrib/postgres/fields/array.py index ae07f1bc0c..65f3dc6f6a 100644 --- a/django/contrib/postgres/fields/array.py +++ b/django/contrib/postgres/fields/array.py @@ -82,7 +82,8 @@ class ArrayField(Field): def deconstruct(self): name, path, args, kwargs = super(ArrayField, self).deconstruct() - path = 'django.contrib.postgres.fields.ArrayField' + if path == 'django.contrib.postgres.fields.array.ArrayField': + path = 'django.contrib.postgres.fields.ArrayField' kwargs.update({ 'base_field': self.base_field, 'size': self.size, diff --git a/tests/postgres_tests/models.py b/tests/postgres_tests/models.py index a119b12f04..d6cf3da786 100644 --- a/tests/postgres_tests/models.py +++ b/tests/postgres_tests/models.py @@ -32,3 +32,8 @@ class CharFieldModel(models.Model): class TextFieldModel(models.Model): field = models.TextField() + + +class ArrayFieldSubclass(ArrayField): + def __init__(self, *args, **kwargs): + super(ArrayFieldSubclass, self).__init__(models.IntegerField()) diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py index 10917153df..5513fb34aa 100644 --- a/tests/postgres_tests/test_array.py +++ b/tests/postgres_tests/test_array.py @@ -10,7 +10,7 @@ from django import forms from django.test import TestCase, override_settings from django.utils import timezone -from .models import IntegerArrayModel, NullableIntegerArrayModel, CharArrayModel, DateTimeArrayModel, NestedIntegerArrayModel +from .models import IntegerArrayModel, NullableIntegerArrayModel, CharArrayModel, DateTimeArrayModel, NestedIntegerArrayModel, ArrayFieldSubclass @unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL required') @@ -228,6 +228,15 @@ class TestMigrations(TestCase): new = ArrayField(*args, **kwargs) self.assertEqual(new.base_field.max_length, field.base_field.max_length) + def test_subclass_deconstruct(self): + field = ArrayField(models.IntegerField()) + name, path, args, kwargs = field.deconstruct() + self.assertEqual(path, 'django.contrib.postgres.fields.ArrayField') + + field = ArrayFieldSubclass() + name, path, args, kwargs = field.deconstruct() + self.assertEqual(path, 'postgres_tests.models.ArrayFieldSubclass') + @override_settings(MIGRATION_MODULES={ "postgres_tests": "postgres_tests.array_default_migrations", })