Skip to content

Commit 5c41658

Browse files
committed
Rename ArrayField.size to max_size
1 parent 2f184a5 commit 5c41658

File tree

8 files changed

+32
-30
lines changed

8 files changed

+32
-30
lines changed

django_mongodb_backend/fields/array.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ class ArrayField(CheckFieldDefaultMixin, Field):
2727
}
2828
_default_hint = ("list", "[]")
2929

30-
def __init__(self, base_field, size=None, **kwargs):
30+
def __init__(self, base_field, max_size=None, **kwargs):
3131
self.base_field = base_field
32-
self.size = size
33-
if self.size:
32+
self.max_size = max_size
33+
if self.max_size:
3434
self.default_validators = [
3535
*self.default_validators,
36-
ArrayMaxLengthValidator(self.size),
36+
ArrayMaxLengthValidator(self.max_size),
3737
]
3838
# For performance, only add a from_db_value() method if the base field
3939
# implements it.
@@ -127,7 +127,7 @@ def deconstruct(self):
127127
kwargs.update(
128128
{
129129
"base_field": self.base_field.clone(),
130-
"size": self.size,
130+
"max_size": self.max_size,
131131
}
132132
)
133133
return name, path, args, kwargs
@@ -213,7 +213,7 @@ def formfield(self, **kwargs):
213213
**{
214214
"form_class": SimpleArrayField,
215215
"base_field": self.base_field.formfield(),
216-
"max_length": self.size,
216+
"max_length": self.max_size,
217217
**kwargs,
218218
}
219219
)

docs/source/ref/models/fields.rst

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ Some MongoDB-specific fields are available in ``django_mongodb_backend.fields``.
88
``ArrayField``
99
--------------
1010

11-
.. class:: ArrayField(base_field, size=None, **options)
11+
.. class:: ArrayField(base_field, max_size=None, **options)
1212

1313
A field for storing lists of data. Most field types can be used, and you
1414
pass another field instance as the :attr:`base_field
15-
<ArrayField.base_field>`. You may also specify a :attr:`size
16-
<ArrayField.size>`. ``ArrayField`` can be nested to store multi-dimensional
17-
arrays.
15+
<ArrayField.base_field>`. You may also specify a :attr:`max_size
16+
<ArrayField.max_size>`. ``ArrayField`` can be nested to store
17+
multi-dimensional arrays.
1818

1919
If you give the field a :attr:`~django.db.models.Field.default`, ensure
2020
it's a callable such as ``list`` (for an empty default) or a callable that
@@ -50,16 +50,16 @@ Some MongoDB-specific fields are available in ``django_mongodb_backend.fields``.
5050
board = ArrayField(
5151
ArrayField(
5252
models.CharField(max_length=10, blank=True),
53-
size=8,
53+
max_size=8,
5454
),
55-
size=8,
55+
max_size=8,
5656
)
5757

5858
Transformation of values between the database and the model, validation
5959
of data and configuration, and serialization are all delegated to the
6060
underlying base field.
6161

62-
.. attribute:: size
62+
.. attribute:: max_size
6363

6464
This is an optional argument.
6565

@@ -168,8 +168,8 @@ Index transforms
168168
^^^^^^^^^^^^^^^^
169169

170170
Index transforms index into the array. Any non-negative integer can be used.
171-
There are no errors if it exceeds the :attr:`size <ArrayField.size>` of the
172-
array. The lookups available after the transform are those from the
171+
There are no errors if it exceeds the :attr:`max_size <ArrayField.max_size>` of
172+
the array. The lookups available after the transform are those from the
173173
:attr:`base_field <ArrayField.base_field>`. For example:
174174

175175
.. code-block:: pycon

docs/source/releases/5.1.x.rst

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Django MongoDB Backend 5.1.x
77

88
*Unreleased*
99

10+
- Backward-incompatible: :class:`~django_mongodb_backend.fields.ArrayField`\'s
11+
``size`` argument is renamed to ``max_size``.
1012
- Added support for :doc:`database caching </topics/cache>`.
1113

1214
5.1.0 beta 1

tests/forms_tests_/test_array.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ def test_model_field_formfield(self):
128128
self.assertIsInstance(form_field.base_field, forms.CharField)
129129
self.assertEqual(form_field.base_field.max_length, 27)
130130

131-
def test_model_field_formfield_size(self):
132-
model_field = ArrayField(models.CharField(max_length=27), size=4)
131+
def test_model_field_formfield_max_size(self):
132+
model_field = ArrayField(models.CharField(max_length=27), max_size=4)
133133
form_field = model_field.formfield()
134134
self.assertIsInstance(form_field, SimpleArrayField)
135135
self.assertEqual(form_field.max_length, 4)

tests/model_fields_/array_default_migrations/0001_initial.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Migration(migrations.Migration):
2121
),
2222
(
2323
"field",
24-
django_mongodb_backend.fields.ArrayField(models.IntegerField(), size=None),
24+
django_mongodb_backend.fields.ArrayField(models.IntegerField(), max_size=None),
2525
),
2626
],
2727
options={},

tests/model_fields_/array_default_migrations/0002_integerarraymodel_field_2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Migration(migrations.Migration):
1313
model_name="integerarraydefaultmodel",
1414
name="field_2",
1515
field=django_mongodb_backend.fields.ArrayField(
16-
models.IntegerField(), default=[], size=None
16+
models.IntegerField(), default=[], max_size=None
1717
),
1818
preserve_default=False,
1919
),

tests/model_fields_/array_index_migrations/0001_initial.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Migration(migrations.Migration):
2222
(
2323
"char",
2424
django_mongodb_backend.fields.ArrayField(
25-
models.CharField(max_length=10), db_index=True, size=100
25+
models.CharField(max_length=10), db_index=True, max_size=100
2626
),
2727
),
2828
("char2", models.CharField(max_length=11, db_index=True)),

tests/model_fields_/test_arrayfield.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ def test_deconstruct(self):
8989
self.assertEqual(type(new.base_field), type(field.base_field))
9090
self.assertIsNot(new.base_field, field.base_field)
9191

92-
def test_deconstruct_with_size(self):
93-
field = ArrayField(models.IntegerField(), size=3)
92+
def test_deconstruct_with_max_size(self):
93+
field = ArrayField(models.IntegerField(), max_size=3)
9494
name, path, args, kwargs = field.deconstruct()
9595
new = ArrayField(*args, **kwargs)
96-
self.assertEqual(new.size, field.size)
96+
self.assertEqual(new.max_size, field.max_size)
9797

9898
def test_deconstruct_args(self):
9999
field = ArrayField(models.CharField(max_length=20))
@@ -722,7 +722,7 @@ class MigrationsTests(TransactionTestCase):
722722
)
723723
def test_adding_field_with_default(self):
724724
class IntegerArrayDefaultModel(models.Model):
725-
field = ArrayField(models.IntegerField(), size=None)
725+
field = ArrayField(models.IntegerField(), max_size=None)
726726

727727
table_name = "model_fields__integerarraydefaultmodel"
728728
self.assertNotIn(table_name, connection.introspection.table_names(None))
@@ -734,8 +734,8 @@ class IntegerArrayDefaultModel(models.Model):
734734
call_command("migrate", "model_fields_", "0002", verbosity=0)
735735

736736
class UpdatedIntegerArrayDefaultModel(models.Model):
737-
field = ArrayField(models.IntegerField(), size=None)
738-
field_2 = ArrayField(models.IntegerField(), default=[], size=None)
737+
field = ArrayField(models.IntegerField(), max_size=None)
738+
field_2 = ArrayField(models.IntegerField(), default=[], max_size=None)
739739

740740
class Meta:
741741
db_table = "model_fields__integerarraydefaultmodel"
@@ -800,8 +800,8 @@ def test_blank_true(self):
800800
# This should not raise a validation error
801801
field.clean([1, None], None)
802802

803-
def test_with_size(self):
804-
field = ArrayField(models.IntegerField(), size=3)
803+
def test_with_max_size(self):
804+
field = ArrayField(models.IntegerField(), max_size=3)
805805
field.clean([1, 2, 3], None)
806806
with self.assertRaises(exceptions.ValidationError) as cm:
807807
field.clean([1, 2, 3, 4], None)
@@ -810,8 +810,8 @@ def test_with_size(self):
810810
"List contains 4 items, it should contain no more than 3.",
811811
)
812812

813-
def test_with_size_singular(self):
814-
field = ArrayField(models.IntegerField(), size=1)
813+
def test_with_max_size_singular(self):
814+
field = ArrayField(models.IntegerField(), max_size=1)
815815
field.clean([1], None)
816816
msg = "List contains 2 items, it should contain no more than 1."
817817
with self.assertRaisesMessage(exceptions.ValidationError, msg):

0 commit comments

Comments
 (0)