Commit 359cc2cd authored by Arnaud Fontaine's avatar Arnaud Fontaine

Delivery: Fix maximum recursion depth in getRootCausalityValueList().

Pattern: SIT_1 => RSPL => SIT_1.

Also, this reduces the complexity by not checking objects twice.
parent 92ffa7f8
...@@ -708,22 +708,29 @@ class Delivery(XMLObject, ImmobilisationDelivery, SimulableMixin, ...@@ -708,22 +708,29 @@ class Delivery(XMLObject, ImmobilisationDelivery, SimulableMixin,
This method will look at the causality and check if the This method will look at the causality and check if the
causality has already a causality causality has already a causality
""" """
seen_set = set()
def recursive(self):
if self in seen_set:
return []
seen_set.add(self)
causality_value_list = self.getCausalityValueList() causality_value_list = self.getCausalityValueList()
if causality_value_list: if causality_value_list:
initial_list = [] initial_list = []
for causality in causality_value_list: for causality in causality_value_list:
# The causality may be something which has not this method # The causality may be something which has not this method
# (e.g. item) # (e.g. item)
try: if getattr(causality, 'getRootCausalityValueList', None) is None:
getRootCausalityValueList = causality.getRootCausalityValueList
except AttributeError:
continue continue
assert causality != self assert causality != self
initial_list += [x for x in getRootCausalityValueList() initial_list += [x for x in recursive(causality)
if x not in initial_list] if x not in initial_list]
return initial_list return initial_list
return [self] return [self]
return recursive(self)
# XXX Temp hack, should be removed has soon as the structure of # XXX Temp hack, should be removed has soon as the structure of
# the order/delivery builder will be reviewed. It might # the order/delivery builder will be reviewed. It might
# be reviewed if we plan to configure movement groups in the zmi # be reviewed if we plan to configure movement groups in the zmi
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment