summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorGavin Wahl <gwahl@fusionbox.com>2014-12-02 18:52:58 -0700
committerTim Graham <timograham@gmail.com>2014-12-03 08:32:59 -0500
commite9975ed3cd3243d78b89fe2b44a152263ba5a602 (patch)
tree555b380100602566c0e343ce6fc7717f13575583 /django
parentde92c61e4043dc0d9cd9f7ea3725798e2017a8a5 (diff)
[1.7.x] Fixed #23950 -- Prevented calling deconstruct on classes in MigrationWriter.
Backport of dee4d23f7e703aec2d1244e4facbf7f4c88deed5 from master
Diffstat (limited to 'django')
-rw-r--r--django/db/migrations/writer.py28
1 files changed, 14 insertions, 14 deletions
diff --git a/django/db/migrations/writer.py b/django/db/migrations/writer.py
index 53ec414335..074a615afe 100644
--- a/django/db/migrations/writer.py
+++ b/django/db/migrations/writer.py
@@ -329,6 +329,20 @@ class MigrationWriter(object):
elif isinstance(value, models.Field):
attr_name, path, args, kwargs = value.deconstruct()
return cls.serialize_deconstructed(path, args, kwargs)
+ # Classes
+ elif isinstance(value, type):
+ special_cases = [
+ (models.Model, "models.Model", []),
+ ]
+ for case, string, imports in special_cases:
+ if case is value:
+ return string, set(imports)
+ if hasattr(value, "__module__"):
+ module = value.__module__
+ if module == six.moves.builtins.__name__:
+ return value.__name__, set()
+ else:
+ return "%s.%s" % (module, value.__name__), {"import %s" % module}
# Anything that knows how to deconstruct itself.
elif hasattr(value, 'deconstruct'):
return cls.serialize_deconstructed(*value.deconstruct())
@@ -362,20 +376,6 @@ class MigrationWriter(object):
"For more information, see https://docs.djangoproject.com/en/1.7/topics/migrations/#serializing-values"
% (value.__name__, module_name))
return "%s.%s" % (module_name, value.__name__), set(["import %s" % module_name])
- # Classes
- elif isinstance(value, type):
- special_cases = [
- (models.Model, "models.Model", []),
- ]
- for case, string, imports in special_cases:
- if case is value:
- return string, set(imports)
- if hasattr(value, "__module__"):
- module = value.__module__
- if module == six.moves.builtins.__name__:
- return value.__name__, set()
- else:
- return "%s.%s" % (module, value.__name__), set(["import %s" % module])
# Other iterables
elif isinstance(value, collections.Iterable):
imports = set()