Skip to content

Commit

Permalink
fix(migrations): do not hang in migrations on broken data
Browse files Browse the repository at this point in the history
When a case's parent work item points to itself, the migration will
loop forever. Catch this situation and abort in that case.
  • Loading branch information
winged committed Sep 25, 2020
1 parent a4985a5 commit bfc4304
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions caluma/caluma_workflow/migrations/0020_case_families.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ def set_family(apps, schema_editor):

for case in orphan_cases:
family = case
while hasattr(family, "parent_work_item"):
family = case.parent_work_item.case
# Navigate up the hierarchy, but avoid hanging
# if we have a loop in the data structure
while (
hasattr(family, "parent_work_item")
and family.parent_work_item.case != family
):
family = family.parent_work_item.case
case.family = family

Case.objects.using(db_alias).bulk_update(orphan_cases, ["family"])
Expand Down

0 comments on commit bfc4304

Please sign in to comment.