From adfdb9f1695d8710456b54282fcc6f306fc918c0 Mon Sep 17 00:00:00 2001 From: Patrik Sletmo Date: Thu, 11 Oct 2018 13:54:37 +0200 Subject: [PATCH] Fixed #29814 -- Added support for NoneType serialization in migrations. --- AUTHORS | 1 + django/db/migrations/serializer.py | 1 + docs/releases/2.2.txt | 2 ++ docs/topics/migrations.txt | 6 +++++- tests/migrations/test_writer.py | 3 +++ 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index ac4ab8410e..9eeca9f580 100644 --- a/AUTHORS +++ b/AUTHORS @@ -651,6 +651,7 @@ answer newbie questions, and generally made Django that much better: Panos Laganakos Pascal Hartig Pascal Varet + Patrik Sletmo Paul Bissex Paul Collier Paul Collins diff --git a/django/db/migrations/serializer.py b/django/db/migrations/serializer.py index 911cf0f359..6fe49e4a8a 100644 --- a/django/db/migrations/serializer.py +++ b/django/db/migrations/serializer.py @@ -252,6 +252,7 @@ class TypeSerializer(BaseSerializer): def serialize(self): special_cases = [ (models.Model, "models.Model", []), + (type(None), 'type(None)', []), ] for case, string, imports in special_cases: if case is self.value: diff --git a/docs/releases/2.2.txt b/docs/releases/2.2.txt index 8f5409e1d1..22d7eee0c1 100644 --- a/docs/releases/2.2.txt +++ b/docs/releases/2.2.txt @@ -188,6 +188,8 @@ Migrations * The new :option:`migrate --plan` option prints the list of migration operations that will be performed. +* ``NoneType`` can now be serialized in migrations. + Models ~~~~~~ diff --git a/docs/topics/migrations.txt b/docs/topics/migrations.txt index 1073ce0cbe..3f0a1fa68c 100644 --- a/docs/topics/migrations.txt +++ b/docs/topics/migrations.txt @@ -666,7 +666,7 @@ for basic values, and doesn't specify import paths). Django can serialize the following: -- ``int``, ``float``, ``bool``, ``str``, ``bytes``, ``None`` +- ``int``, ``float``, ``bool``, ``str``, ``bytes``, ``None``, ``NoneType`` - ``list``, ``set``, ``tuple``, ``dict`` - ``datetime.date``, ``datetime.time``, and ``datetime.datetime`` instances (include those that are timezone-aware) @@ -686,6 +686,10 @@ Django can serialize the following: Serialization support for :class:`functools.partialmethod` was added. +.. versionchanged:: 2.2 + + Serialization support for ``NoneType`` was added. + Django cannot serialize: - Nested classes diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py index c656f95666..f7ec6f4bd3 100644 --- a/tests/migrations/test_writer.py +++ b/tests/migrations/test_writer.py @@ -513,6 +513,9 @@ class WriterTests(SimpleTestCase): self.assertEqual(result.args, value.args) self.assertEqual(result.keywords, value.keywords) + def test_serialize_type_none(self): + self.assertSerializedEqual(type(None)) + def test_simple_migration(self): """ Tests serializing a simple migration.