Fixed #30350 -- Prevented recreation of migration for operations with a range object.

Thanks to Mariusz Felisiak for helping with the patch.
This commit is contained in:
Florian Apolloner 2019-04-13 15:03:26 +02:00 committed by Mariusz Felisiak
parent 1afbc96a75
commit 2e38f2015a
No known key found for this signature in database
GPG Key ID: 2EF56372BA48CD1B
3 changed files with 10 additions and 1 deletions

View File

@ -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,

View File

@ -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`).

View File

@ -451,6 +451,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')