Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle CircularDependencyException at the topmost level of operation ordering #167

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions wagtail_transfer/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,20 @@ def run(self):

# arrange operations into an order that satisfies dependencies
operation_order = []
for operation in satisfiable_operations:
self._add_to_operation_order(operation, operation_order, [operation])
while satisfiable_operations:
held_operations = []
for operation in satisfiable_operations:
try:
self._add_to_operation_order(operation, operation_order, [operation])
except CircularDependencyException as e:
# if the exception has propagated to this level it ought to be a soft dependency,
# as otherwise it should have been caught by _check_satisfiable.
# Hold it back to retry adding later
held_operations.append(operation)
if len(held_operations) == len(satisfiable_operations):
# Not managed to add any of the operations - can't proceed
raise CircularDependencyException("Unsatisfiable circular dependency found")
satisfiable_operations = held_operations

# run operations in order
with transaction.atomic():
Expand Down