diff options
Diffstat (limited to 'archaeological_warehouse/models.py')
-rw-r--r-- | archaeological_warehouse/models.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index a72d5a214..add786012 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -1274,6 +1274,22 @@ class Container( def _get_base_image_path(self): return self.location._get_base_image_path() + "/" + self.external_id + def _prevent_parent_infinite_loop(self) -> bool: + """ + Check there is no infinite loop in parents. If a loop is detected, set the + parent to null. + :return: True if parent has been changed + """ + parent = self.parent + parents = [] + while parent: + if parent.id in parents: + self.parent = None # break the loop arbitrary + return True + parents.append(parent.id) + parent = parent.parent + return False + @classmethod def _change_child_location(cls, parent): for child in ( @@ -1742,9 +1758,10 @@ class Container( self.pre_save() super(Container, self).save(*args, **kwargs) self._change_child_location(self) + updated = False + updated += self._prevent_parent_infinite_loop() self._update_warehouse_max_division() - updated = False updated += self._calculate_weight() if not self.index and not self.container_type.stationary: |