Skip to content

Commit

Permalink
[2.2.x] Fixed #30350 -- Prevented recreation of migration for operati…
Browse files Browse the repository at this point in the history
…ons with a range object.

Thanks to Mariusz Felisiak for helping with the patch.

Backport of 2e38f20 from master.
  • Loading branch information
apollo13 authored and felixxm committed Apr 14, 2019
1 parent 5ed5ce5 commit 896cc71
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django/db/migrations/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 4 additions & 0 deletions docs/releases/2.2.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
5 changes: 5 additions & 0 deletions tests/migrations/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,11 @@ def test_serialize_empty_nonempty_tuple(self):
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')
Expand Down

0 comments on commit 896cc71

Please sign in to comment.