1
0
mirror of https://github.com/django/django.git synced 2025-04-06 06:26:41 +00:00

Fixed #36276 -- Omitted size=None from ArrayField.deconstruct().

This commit is contained in:
Tim Graham 2025-03-24 21:18:58 -04:00 committed by Sarah Boyce
parent 7164f08047
commit fecca298a2
5 changed files with 19 additions and 30 deletions

View File

@ -134,12 +134,9 @@ class ArrayField(CheckFieldDefaultMixin, Field):
name, path, args, kwargs = super().deconstruct()
if path == "django.contrib.postgres.fields.array.ArrayField":
path = "django.contrib.postgres.fields.ArrayField"
kwargs.update(
{
"base_field": self.base_field.clone(),
"size": self.size,
}
)
kwargs["base_field"] = self.base_field.clone()
if self.size is not None:
kwargs["size"] = self.size
return name, path, args, kwargs
def to_python(self, value):

View File

@ -20,9 +20,7 @@ class Migration(migrations.Migration):
),
(
"field",
django.contrib.postgres.fields.ArrayField(
models.IntegerField(), size=None
),
django.contrib.postgres.fields.ArrayField(models.IntegerField()),
),
],
options={},

View File

@ -12,7 +12,7 @@ class Migration(migrations.Migration):
model_name="integerarraydefaultmodel",
name="field_2",
field=django.contrib.postgres.fields.ArrayField(
models.IntegerField(), default=[], size=None
models.IntegerField(), default=[]
),
preserve_default=False,
),

View File

@ -32,7 +32,7 @@ class Migration(migrations.Migration):
primary_key=True,
),
),
("field", ArrayField(models.CharField(max_length=10), size=None)),
("field", ArrayField(models.CharField(max_length=10))),
],
options={
"required_db_vendor": "postgresql",
@ -51,9 +51,9 @@ class Migration(migrations.Migration):
primary_key=True,
),
),
("datetimes", ArrayField(models.DateTimeField(), size=None)),
("dates", ArrayField(models.DateField(), size=None)),
("times", ArrayField(models.TimeField(), size=None)),
("datetimes", ArrayField(models.DateTimeField())),
("dates", ArrayField(models.DateField())),
("times", ArrayField(models.TimeField())),
],
options={
"required_db_vendor": "postgresql",
@ -94,21 +94,20 @@ class Migration(migrations.Migration):
),
(
"ips",
ArrayField(models.GenericIPAddressField(), size=None, default=list),
ArrayField(models.GenericIPAddressField(), default=list),
),
("uuids", ArrayField(models.UUIDField(), size=None, default=list)),
("uuids", ArrayField(models.UUIDField(), default=list)),
(
"decimals",
ArrayField(
models.DecimalField(max_digits=5, decimal_places=2),
size=None,
default=list,
),
),
("tags", ArrayField(TagField(), blank=True, null=True, size=None)),
("tags", ArrayField(TagField(), blank=True, null=True)),
(
"json",
ArrayField(models.JSONField(default=dict), default=list, size=None),
ArrayField(models.JSONField(default=dict), default=list),
),
("int_ranges", ArrayField(IntegerRangeField(), null=True, blank=True)),
(
@ -135,9 +134,7 @@ class Migration(migrations.Migration):
),
(
"field",
ArrayField(
models.IntegerField(), blank=True, default=list, size=None
),
ArrayField(models.IntegerField(), blank=True, default=list),
),
],
options={
@ -159,7 +156,7 @@ class Migration(migrations.Migration):
),
(
"field",
ArrayField(ArrayField(models.IntegerField(), size=None), size=None),
ArrayField(ArrayField(models.IntegerField())),
),
],
options={
@ -203,15 +200,11 @@ class Migration(migrations.Migration):
),
(
"field",
ArrayField(models.IntegerField(), size=None, null=True, blank=True),
ArrayField(models.IntegerField(), null=True, blank=True),
),
(
"field_nested",
ArrayField(
ArrayField(models.IntegerField(null=True), size=None),
size=None,
null=True,
),
ArrayField(ArrayField(models.IntegerField(null=True)), null=True),
),
("order", models.IntegerField(null=True)),
],
@ -524,7 +517,7 @@ class Migration(migrations.Migration):
),
(
"array_of_enums",
ArrayField(EnumField(max_length=20), size=None),
ArrayField(EnumField(max_length=20)),
),
],
options={

View File

@ -923,6 +923,7 @@ class TestMigrations(TransactionTestCase):
def test_deconstruct(self):
field = ArrayField(models.IntegerField())
name, path, args, kwargs = field.deconstruct()
self.assertEqual(kwargs.keys(), {"base_field"})
new = ArrayField(*args, **kwargs)
self.assertEqual(type(new.base_field), type(field.base_field))
self.assertIsNot(new.base_field, field.base_field)