In loadentities command detect loops before loading entities

This commit is contained in:
Benjamin Dauvergne 2015-01-09 12:15:36 +01:00
parent 60399803ad
commit fc98a4e129
1 changed files with 4 additions and 2 deletions

View File

@ -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)