mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[1.7.x] Fixed #23950 -- Prevented calling deconstruct on classes in MigrationWriter.
Backport of dee4d23f7e from master
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user