Skip to content

Commit 5756eb9

Browse files
committed
fix: Add exception handling to prevent approval status rollback
Wrap post-approval actions (execute_post_approval_updates, execute_post_submission_actions, execute_file_workflow_hooks) with try/except blocks in _finalize_submission() and _reject_submission() to prevent failures in these non-critical operations from rolling back the submission status update. This fixes an issue where approval/rejection would be recorded on the task but the submission status would remain unchanged if any post-action failed (e.g., Celery broker unavailable). Bump version to 0.6.5
1 parent 0c60ec0 commit 5756eb9

3 files changed

Lines changed: 41 additions & 12 deletions

File tree

django_forms_workflows/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Enterprise-grade, database-driven form builder with approval workflows
44
"""
55

6-
__version__ = "0.6.4"
6+
__version__ = "0.6.5"
77
__author__ = "Django Forms Workflows Contributors"
88
__license__ = "LGPL-3.0-only"
99

django_forms_workflows/workflow_engine.py

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,23 @@ def _finalize_submission(submission: FormSubmission) -> None:
6565
# Cancel any remaining pending tasks
6666
submission.approval_tasks.filter(status="pending").update(status="skipped")
6767

68-
execute_post_approval_updates(submission)
69-
execute_post_submission_actions(submission, "on_complete")
70-
execute_file_workflow_hooks(submission, "on_approve")
68+
# Execute post-approval actions with exception handling to prevent
69+
# failures from affecting the submission status update
70+
try:
71+
execute_post_approval_updates(submission)
72+
except Exception as e:
73+
logger.error("Error in execute_post_approval_updates: %s", e, exc_info=True)
74+
75+
try:
76+
execute_post_submission_actions(submission, "on_complete")
77+
except Exception as e:
78+
logger.error("Error in execute_post_submission_actions: %s", e, exc_info=True)
79+
80+
try:
81+
execute_file_workflow_hooks(submission, "on_approve")
82+
except Exception as e:
83+
logger.error("Error in execute_file_workflow_hooks: %s", e, exc_info=True)
84+
7185
_notify_final_approval(submission)
7286

7387

@@ -80,15 +94,30 @@ def _reject_submission(submission: FormSubmission, reason: str = "") -> None:
8094
# Cancel any remaining pending tasks
8195
submission.approval_tasks.filter(status="pending").update(status="skipped")
8296

83-
# Execute rejection actions
84-
execute_post_submission_actions(submission, "on_reject")
85-
execute_file_workflow_hooks(submission, "on_reject")
97+
# Execute rejection actions with exception handling to prevent
98+
# failures from affecting the submission status update
99+
try:
100+
execute_post_submission_actions(submission, "on_reject")
101+
except Exception as e:
102+
logger.error(
103+
"Error in execute_post_submission_actions (on_reject): %s", e, exc_info=True
104+
)
105+
106+
try:
107+
execute_file_workflow_hooks(submission, "on_reject")
108+
except Exception as e:
109+
logger.error(
110+
"Error in execute_file_workflow_hooks (on_reject): %s", e, exc_info=True
111+
)
86112

87113
# Mark all managed files as rejected
88-
for managed_file in submission.managed_files.filter(
89-
is_current=True, status="pending"
90-
):
91-
managed_file.mark_rejected(notes=reason)
114+
try:
115+
for managed_file in submission.managed_files.filter(
116+
is_current=True, status="pending"
117+
):
118+
managed_file.mark_rejected(notes=reason)
119+
except Exception as e:
120+
logger.error("Error marking managed files as rejected: %s", e, exc_info=True)
92121

93122

94123
# --- Public API -------------------------------------------------------------

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "django-forms-workflows"
3-
version = "0.6.4"
3+
version = "0.6.5"
44
description = "Enterprise-grade, database-driven form builder with approval workflows and external data integration"
55
license = "LGPL-3.0-only"
66
readme = "README.md"

0 commit comments

Comments
 (0)