Allow serializing NoneType in migrations
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)
| Easy pickings: |
unset
|
| Summary: |
Migrations deconstructing NoneType → Allow serializing NoneType in migrations
|
| Triage Stage: |
Unreviewed → Accepted
|
| Owner: |
changed from nobody to Patrik Sletmo
|
| Status: |
new → assigned
|
| Triage Stage: |
Accepted → Ready for checkin
|
| Version: |
2.1 → master
|
| Resolution: |
→ fixed
|
| Status: |
assigned → closed
|
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)))