Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fixed #20978 -- MigrationWriter.serialize and closures. #1542

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
3 participants
Member

loic commented Sep 1, 2013

No description provided.

@MarkusH MarkusH and 1 other commented on an outdated diff Sep 2, 2013

django/db/migrations/writer.py
@@ -153,10 +157,13 @@ def serialize(cls, value):
module = klass.__module__
return "%s.%s.%s" % (module, klass.__name__, value.__name__), set(["import %s" % module])
else:
- module = value.__module__
- if module is None:
- raise ValueError("Cannot serialize function %r: No module" % value)
- return "%s.%s" % (module, value.__name__), set(["import %s" % module])
+ if hasattr(value, 'deconstruct'):
+ return cls.reconstruct(*value.deconstruct())
+ else:
+ module = value.__module__
+ if module is None:
+ raise ValueError("Cannot serialize function %r: No module" % value)
@MarkusH

MarkusH Sep 2, 2013

Member

I'm thinking about adding a hint to provide a deconstruct attribute function for value.

@loic

loic Sep 3, 2013

Member

As discussed on IRC (replying in case another reviewer is wondering), if you reach here, your function doesn't have a deconstruct attribute.

Member

loic commented Sep 7, 2013

Renamed MigrationWriter.reconstruct to serialize_deconstructed to account for @andrewgodwin's feedback that reconstruct is not the strict reverse of deconstruct since it returns a string+imports rather than a field instance.

Owner

timgraham commented Sep 10, 2013

merged in 5df8f74 and d59f199 - thanks!

@timgraham timgraham closed this Sep 10, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment