From dee4d23f7e703aec2d1244e4facbf7f4c88deed5 Mon Sep 17 00:00:00 2001 From: Gavin Wahl Date: Tue, 2 Dec 2014 18:52:58 -0700 Subject: Fixed #23950 -- Prevented calling deconstruct on classes in MigrationWriter. --- django/db/migrations/writer.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'django') diff --git a/django/db/migrations/writer.py b/django/db/migrations/writer.py index 1e093778a5..dec0eae33d 100644 --- a/django/db/migrations/writer.py +++ b/django/db/migrations/writer.py @@ -330,6 +330,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()) @@ -364,20 +378,6 @@ class MigrationWriter(object): "https://docs.djangoproject.com/en/dev/topics/migrations/#serializing-values" % (value.__name__, module_name)) return "%s.%s" % (module_name, value.__name__), {"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__), {"import %s" % module} # Other iterables elif isinstance(value, collections.Iterable): imports = set() -- cgit v1.3