diff options
| author | Markus Holtermann <info@markusholtermann.eu> | 2014-09-08 03:01:42 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-09-08 15:41:14 -0400 |
| commit | b0def3bcac1a2e1117050e00fa1b187a897f0c2e (patch) | |
| tree | 1fb5180b17a02aa636aa80f69d7f87a8f4809452 /django/utils/deconstruct.py | |
| parent | 9c4fb019cb76eb3314357a18e225a63e113dc1fd (diff) | |
[1.7.x] Fixed #23418 -- Fail when migration deconstruct produces invalid import
Backport of d28b5f13b3 from master
Diffstat (limited to 'django/utils/deconstruct.py')
| -rw-r--r-- | django/utils/deconstruct.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/django/utils/deconstruct.py b/django/utils/deconstruct.py index 7774e69997..627c2a9c68 100644 --- a/django/utils/deconstruct.py +++ b/django/utils/deconstruct.py @@ -1,3 +1,5 @@ +from importlib import import_module + def deconstructible(*args, **kwargs): """ Class decorator that allow the decorated class to be serialized @@ -19,8 +21,25 @@ def deconstructible(*args, **kwargs): Returns a 3-tuple of class import path, positional arguments, and keyword arguments. """ + # Python 2/fallback version + if path: + module_name, _, name = path.rpartition('.') + else: + module_name = obj.__module__ + name = obj.__class__.__name__ + # Make sure it's actually there and not an inner class + module = import_module(module_name) + if not hasattr(module, name): + raise ValueError( + "Could not find object %s in %s.\n" + "Please note that you cannot serialize things like inner " + "classes. Please move the object into the main module " + "body to use migrations.\n" + "For more information, see " + "https://docs.djangoproject.com/en/dev/topics/migrations/#serializing-values" + % (name, module_name)) return ( - path or '%s.%s' % (obj.__class__.__module__, obj.__class__.__name__), + path or '%s.%s' % (obj.__class__.__module__, name), obj._constructor_args[0], obj._constructor_args[1], ) |
