From 736fb1838cc25f5faf57cd2a4f6b6ab32ff9aadc Mon Sep 17 00:00:00 2001 From: Markus Holtermann Date: Fri, 26 Jun 2015 15:05:55 +0200 Subject: [PATCH] Used field.clone() where applicable --- django/db/migrations/state.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/django/db/migrations/state.py b/django/db/migrations/state.py index b1cba07a9e0..33362ed06fa 100644 --- a/django/db/migrations/state.py +++ b/django/db/migrations/state.py @@ -357,10 +357,9 @@ class ModelState(object): continue if isinstance(field, OrderWrt): continue - name, path, args, kwargs = field.deconstruct() - field_class = import_string(path) + name = force_text(field.name, strings_only=True) try: - fields.append((name, field_class(*args, **kwargs))) + fields.append((name, field.clone())) except TypeError as e: raise TypeError("Couldn't reconstruct field %s on %s: %s" % ( name, @@ -369,10 +368,9 @@ class ModelState(object): )) if not exclude_rels: for field in model._meta.local_many_to_many: - name, path, args, kwargs = field.deconstruct() - field_class = import_string(path) + name = force_text(field.name, strings_only=True) try: - fields.append((name, field_class(*args, **kwargs))) + fields.append((name, field.clone())) except TypeError as e: raise TypeError("Couldn't reconstruct m2m field %s on %s: %s" % ( name, @@ -499,13 +497,6 @@ class ModelState(object): } return value - def construct_fields(self): - "Deep-clone the fields using deconstruction" - for name, field in self.fields: - _, path, args, kwargs = field.deconstruct() - field_class = import_string(path) - yield name, field_class(*args, **kwargs) - def construct_managers(self): "Deep-clone the managers using deconstruction" # Sort all managers by their creation counter @@ -546,7 +537,7 @@ class ModelState(object): except LookupError: raise InvalidBasesError("Cannot resolve one or more bases from %r" % (self.bases,)) # Turn fields into a dict for the body, add other bits - body = dict(self.construct_fields()) + body = {name: field.clone() for name, field in self.fields} body['Meta'] = meta body['__module__'] = "__fake__"