diff --git a/django/db/migrations/serializer.py b/django/db/migrations/serializer.py index ace0a860c4..5e45f1eaa9 100644 --- a/django/db/migrations/serializer.py +++ b/django/db/migrations/serializer.py @@ -284,7 +284,7 @@ class Serializer: ((datetime.date, datetime.timedelta, datetime.time), DateTimeSerializer), (SettingsReference, SettingsReferenceSerializer), (float, FloatSerializer), - ((bool, int, type(None), bytes, str), BaseSimpleSerializer), + ((bool, int, type(None), bytes, str, range), BaseSimpleSerializer), (decimal.Decimal, DecimalSerializer), ((functools.partial, functools.partialmethod), FunctoolsPartialSerializer), ((types.FunctionType, types.BuiltinFunctionType, types.MethodType), FunctionTypeSerializer), diff --git a/docs/releases/2.2.1.txt b/docs/releases/2.2.1.txt index 2b82a33d29..dcad58b2fd 100644 --- a/docs/releases/2.2.1.txt +++ b/docs/releases/2.2.1.txt @@ -25,3 +25,7 @@ Bugfixes * Fixed a regression in Django 2.2 that caused a single instance fast-delete to not set the primary key to ``None`` (:ticket:`30330`). + +* Prevented :djadmin:`makemigrations` from generating infinite migrations for + check constraints and partial indexes when ``condition`` contains + a :class:`~python:range` object (:ticket:`30350`). diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py index abeeaf5182..25637eb070 100644 --- a/tests/migrations/test_writer.py +++ b/tests/migrations/test_writer.py @@ -455,6 +455,11 @@ class WriterTests(SimpleTestCase): self.assertSerializedEqual(one_item_tuple) self.assertSerializedEqual(many_items_tuple) + def test_serialize_range(self): + string, imports = MigrationWriter.serialize(range(1, 5)) + self.assertEqual(string, 'range(1, 5)') + self.assertEqual(imports, set()) + def test_serialize_builtins(self): string, imports = MigrationWriter.serialize(range) self.assertEqual(string, 'range')