Browse Source

Fixed #29814 -- Added support for NoneType serialization in migrations.

Patrik Sletmo 6 years ago
parent
commit
adfdb9f169

+ 1 - 0
AUTHORS

@@ -651,6 +651,7 @@ answer newbie questions, and generally made Django that much better:
     Panos Laganakos <panos.laganakos@gmail.com>
     Pascal Hartig <phartig@rdrei.net>
     Pascal Varet
+    Patrik Sletmo <patrik.sletmo@gmail.com>
     Paul Bissex <http://e-scribe.com/>
     Paul Collier <paul@paul-collier.com>
     Paul Collins <paul.collins.iii@gmail.com>

+ 1 - 0
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:

+ 2 - 0
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
 ~~~~~~
 

+ 5 - 1
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

+ 3 - 0
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.