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

This commit is contained in:
Patrik Sletmo 2018-10-11 13:54:37 +02:00 committed by Tim Graham
parent 52fec5d18f
commit adfdb9f169
5 changed files with 12 additions and 1 deletions

View File

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

View File

@ -252,6 +252,7 @@ class TypeSerializer(BaseSerializer):
def serialize(self): def serialize(self):
special_cases = [ special_cases = [
(models.Model, "models.Model", []), (models.Model, "models.Model", []),
(type(None), 'type(None)', []),
] ]
for case, string, imports in special_cases: for case, string, imports in special_cases:
if case is self.value: if case is self.value:

View File

@ -188,6 +188,8 @@ Migrations
* The new :option:`migrate --plan` option prints the list of migration * The new :option:`migrate --plan` option prints the list of migration
operations that will be performed. operations that will be performed.
* ``NoneType`` can now be serialized in migrations.
Models Models
~~~~~~ ~~~~~~

View File

@ -666,7 +666,7 @@ for basic values, and doesn't specify import paths).
Django can serialize the following: Django can serialize the following:
- ``int``, ``float``, ``bool``, ``str``, ``bytes``, ``None`` - ``int``, ``float``, ``bool``, ``str``, ``bytes``, ``None``, ``NoneType``
- ``list``, ``set``, ``tuple``, ``dict`` - ``list``, ``set``, ``tuple``, ``dict``
- ``datetime.date``, ``datetime.time``, and ``datetime.datetime`` instances - ``datetime.date``, ``datetime.time``, and ``datetime.datetime`` instances
(include those that are timezone-aware) (include those that are timezone-aware)
@ -686,6 +686,10 @@ Django can serialize the following:
Serialization support for :class:`functools.partialmethod` was added. Serialization support for :class:`functools.partialmethod` was added.
.. versionchanged:: 2.2
Serialization support for ``NoneType`` was added.
Django cannot serialize: Django cannot serialize:
- Nested classes - Nested classes

View File

@ -513,6 +513,9 @@ class WriterTests(SimpleTestCase):
self.assertEqual(result.args, value.args) self.assertEqual(result.args, value.args)
self.assertEqual(result.keywords, value.keywords) self.assertEqual(result.keywords, value.keywords)
def test_serialize_type_none(self):
self.assertSerializedEqual(type(None))
def test_simple_migration(self): def test_simple_migration(self):
""" """
Tests serializing a simple migration. Tests serializing a simple migration.