summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorRainer Koirikivi <rainer@koirikivi.fi>2013-08-21 03:21:21 +0300
committerRamiro Morales <cramm0@gmail.com>2014-05-11 19:50:01 -0300
commita75324c6544d728d3bd8f678b1b8021fdff18332 (patch)
treef160985f7eab70f9c8adbcafdafca20f378efff6 /django
parent63df886df728c35d3b12da6a03062b46d84d8978 (diff)
Fixed #14226 -- Dependency calculation for complex M2M relations.
`sort_dependencies` incorrectly interpreted 'complex' M2M relations (with explicit through models) as dependencies for a model. This caused circular complex M2M relations to be unserializable by dumpdata. Thanks to aneil for the report and outofculture for initial tests.
Diffstat (limited to 'django')
-rw-r--r--django/core/management/commands/dumpdata.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/django/core/management/commands/dumpdata.py b/django/core/management/commands/dumpdata.py
index c54ccc1c58..b28ad59083 100644
--- a/django/core/management/commands/dumpdata.py
+++ b/django/core/management/commands/dumpdata.py
@@ -189,17 +189,21 @@ def sort_dependencies(app_list):
else:
deps = []
- # Now add a dependency for any FK or M2M relation with
- # a model that defines a natural key
+ # Now add a dependency for any FK relation with a model that
+ # defines a natural key
for field in model._meta.fields:
if hasattr(field.rel, 'to'):
rel_model = field.rel.to
if hasattr(rel_model, 'natural_key') and rel_model != model:
deps.append(rel_model)
+ # Also add a dependency for any simple M2M relation with a model
+ # that defines a natural key. M2M relations with explicit through
+ # models don't count as dependencies.
for field in model._meta.many_to_many:
- rel_model = field.rel.to
- if hasattr(rel_model, 'natural_key') and rel_model != model:
- deps.append(rel_model)
+ if field.rel.through._meta.auto_created:
+ rel_model = field.rel.to
+ if hasattr(rel_model, 'natural_key') and rel_model != model:
+ deps.append(rel_model)
model_dependencies.append((model, deps))
model_dependencies.reverse()