Opened 6 years ago

Closed 6 years ago

#29814 closed Bug (fixed)

Allow serializing NoneType in migrations

Reported by: Daan van der Kallen Owned by: Patrik Sletmo
Component: Migrations Version: dev
Severity: Normal Keywords: migration deconstruct nonetype none
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When in a deconstructible class used in a migration one of the arguments to instantiate the class is the NoneType (aka type(None)) this is just serialized as NoneType which will throw a NameError because it is not defined. The only way to get this value in Python 3 is with type(None) so simply serializing NoneType as type(None) should already do the trick.

Change History (5)

comment:1 by Tim Graham, 6 years ago

Easy pickings: unset
Summary: Migrations deconstructing NoneTypeAllow serializing NoneType in migrations
Triage Stage: UnreviewedAccepted

comment:2 by Patrik Sletmo, 6 years ago

Owner: changed from nobody to Patrik Sletmo
Status: newassigned

I've managed to reproduce the issue and will attempt to provide a patch later this week. If anyone is interested in reproducing the issue on their own, the following code generates a problematic migration:

from django.db import models
from django.utils.deconstruct import deconstructible


@deconstructible
class SerializableClass:
    def __init__(self, foo):
        self.foo = foo


class DemoModel(models.Model):
    problematic_field = models.Field(default=SerializableClass(type(None)))

comment:3 by Patrik Sletmo, 6 years ago

Has patch: set

comment:4 by Simon Charette, 6 years ago

Triage Stage: AcceptedReady for checkin
Version: 2.1master

comment:5 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In adfdb9f1:

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

Note: See TracTickets for help on using tickets.
Back to Top