summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2015-09-16 09:10:59 -0400
committerTim Graham <timograham@gmail.com>2015-09-17 10:06:52 -0400
commit7506616f164a0e2a63fd8bf5ca044ddb78f9b22a (patch)
tree248a512d3d72ed85fc9706975a896bcf17eaf3f7
parentda5747f8e460ea2a2d16f124463b3975ccfc0992 (diff)
Refs #24215 -- Fixed Python 3.5 compatiblity for unhandled lazy ops error.
-rw-r--r--django/apps/registry.py4
-rw-r--r--django/db/migrations/state.py8
2 files changed, 7 insertions, 5 deletions
diff --git a/django/apps/registry.py b/django/apps/registry.py
index 46c10ef4fb..3484d87aee 100644
--- a/django/apps/registry.py
+++ b/django/apps/registry.py
@@ -381,6 +381,10 @@ class Apps(object):
def function(model):
next_function = partial(supplied_fn, model)
+ # Annotate the function with its field for retrieval in
+ # migrations.state.StateApps.
+ if getattr(supplied_fn, 'keywords', None):
+ next_function.field = supplied_fn.keywords.get('field')
self.lazy_model_operation(next_function, *more_models)
# If the model is already loaded, pass it to the function immediately.
diff --git a/django/db/migrations/state.py b/django/db/migrations/state.py
index 3613ae2a4d..2365e39ab6 100644
--- a/django/db/migrations/state.py
+++ b/django/db/migrations/state.py
@@ -244,11 +244,9 @@ class StateApps(Apps):
has a keyword argument called 'field'.
"""
def extract_field(operation):
- # Expect a functools.partial() with a kwarg called 'field' applied.
- try:
- return operation.func.keywords['field']
- except (AttributeError, KeyError):
- return None
+ # operation is annotated with the field in
+ # apps.register.Apps.lazy_model_operation().
+ return getattr(operation, 'field', None)
def extract_field_names(operations):
return (str(field) for field in map(extract_field, operations) if field)