From fc98a4e129f792841dea0b14a26663bafead910b Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 9 Jan 2015 12:15:36 +0100 Subject: [PATCH] In loadentities command detect loops before loading entities --- polynum/base/management/commands/loadentities.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/polynum/base/management/commands/loadentities.py b/polynum/base/management/commands/loadentities.py index 6bba5a5..26a83f9 100644 --- a/polynum/base/management/commands/loadentities.py +++ b/polynum/base/management/commands/loadentities.py @@ -108,14 +108,16 @@ class Command(BaseCommand): make_option("--xml", action="store_true"), make_option("--test", action="store_true"),) - def build_parents_relations(self, relations, entity, current=None, direct=True, depth=0): + def build_parents_relations(self, relations, entity, current=None, direct=True, depth=0, path=[]): if not current: current = entity entity.depth = max(entity.depth, depth) + if current.code in path: + raise Exception('loop detected: %s' % ([current.code] + path)) for parent_entity in current.parents: relations.add((parent_entity, entity, direct)) self.build_parents_relations(relations, entity, - current=parent_entity, direct=False, depth=depth+1) + current=parent_entity, direct=False, depth=depth+1, path=[current.code]+path) def allocate_instances(self, entity, left_bound, instances, path, depth=0, parent=None): instance = self.old_instances.get(path)