mirror of https://github.com/django/django.git
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.
This commit is contained in:
parent
07728a2c2c
commit
7c50e7eecc
|
@ -82,7 +82,8 @@ class ArrayField(Field):
|
||||||
|
|
||||||
def deconstruct(self):
|
def deconstruct(self):
|
||||||
name, path, args, kwargs = super(ArrayField, self).deconstruct()
|
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({
|
kwargs.update({
|
||||||
'base_field': self.base_field,
|
'base_field': self.base_field,
|
||||||
'size': self.size,
|
'size': self.size,
|
||||||
|
|
|
@ -32,3 +32,8 @@ class CharFieldModel(models.Model):
|
||||||
|
|
||||||
class TextFieldModel(models.Model):
|
class TextFieldModel(models.Model):
|
||||||
field = models.TextField()
|
field = models.TextField()
|
||||||
|
|
||||||
|
|
||||||
|
class ArrayFieldSubclass(ArrayField):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(ArrayFieldSubclass, self).__init__(models.IntegerField())
|
||||||
|
|
|
@ -10,7 +10,7 @@ from django import forms
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
from django.utils import timezone
|
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')
|
@unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL required')
|
||||||
|
@ -228,6 +228,15 @@ class TestMigrations(TestCase):
|
||||||
new = ArrayField(*args, **kwargs)
|
new = ArrayField(*args, **kwargs)
|
||||||
self.assertEqual(new.base_field.max_length, field.base_field.max_length)
|
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={
|
@override_settings(MIGRATION_MODULES={
|
||||||
"postgres_tests": "postgres_tests.array_default_migrations",
|
"postgres_tests": "postgres_tests.array_default_migrations",
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue