diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-11-09 11:08:30 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-11-09 11:13:14 +0100 |
commit | 1c42e77089448a010f661ef3d258aee8c712f1c3 (patch) | |
tree | b0d3b4ec1ff5b17bdebe26cb0338638c3e8add18 /archaeological_warehouse/models.py | |
parent | 0c7b6b04b8f603c548b3deb6c7607d9f45fda365 (diff) | |
download | Ishtar-1c42e77089448a010f661ef3d258aee8c712f1c3.tar.bz2 Ishtar-1c42e77089448a010f661ef3d258aee8c712f1c3.zip |
Container: prevent parent infinite loop
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: |