From 896cc7190115c5bcdef756fe10dc203d9b03678c Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Sat, 13 Apr 2019 15:03:26 +0200 Subject: [PATCH] [2.2.x] Fixed #30350 -- Prevented recreation of migration for operations with a range object. Thanks to Mariusz Felisiak for helping with the patch. Backport of 2e38f2015aba224b68a91a3012b87223f3046bb6 from master. --- django/db/migrations/serializer.py | 2 +- docs/releases/2.2.1.txt | 4 ++++ tests/migrations/test_writer.py | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) 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')