From 761023c6214f09c48b0d323ad452cb8480afcce9 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 26 Jan 2023 18:26:17 -0500 Subject: [PATCH 1/4] Workflow Data Exceptions were not getting processed, we now catch the WorkflowDataException through the generic top level SpiffWorkflowException. --- spiffworkflow-backend/pyproject.toml | 4 ++-- .../spiffworkflow_backend/exceptions/api_error.py | 12 +++++++----- .../services/process_instance_processor.py | 8 ++++---- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/spiffworkflow-backend/pyproject.toml b/spiffworkflow-backend/pyproject.toml index 9f8a29443..da45e6848 100644 --- a/spiffworkflow-backend/pyproject.toml +++ b/spiffworkflow-backend/pyproject.toml @@ -29,8 +29,8 @@ flask-restful = "*" werkzeug = "*" # temporarily switch off main to fix CI because poetry export doesn't capture the revision if it's not here (it ignores the lock) # SpiffWorkflow = {git = "https://github.com/sartography/SpiffWorkflow", rev = "main"} -SpiffWorkflow = {git = "https://github.com/sartography/SpiffWorkflow", rev = "450ef3bcd639b6bc1c115fbe35bf3f93946cb0c7"} -# SpiffWorkflow = {develop = true, path = "../SpiffWorkflow" } +# SpiffWorkflow = {git = "https://github.com/sartography/SpiffWorkflow", rev = "450ef3bcd639b6bc1c115fbe35bf3f93946cb0c7"} +SpiffWorkflow = {develop = true, path = "../SpiffWorkflow" } sentry-sdk = "^1.10" sphinx-autoapi = "^2.0" flask-bpmn = {git = "https://github.com/sartography/flask-bpmn", rev = "main"} diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/exceptions/api_error.py b/spiffworkflow-backend/src/spiffworkflow_backend/exceptions/api_error.py index 02a66a207..58821d0c2 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/exceptions/api_error.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/exceptions/api_error.py @@ -8,6 +8,7 @@ from typing import Any import flask.wrappers import sentry_sdk +from SpiffWorkflow.bpmn.exceptions import WorkflowDataException from flask import Blueprint from flask import current_app from flask import g @@ -15,7 +16,7 @@ from flask import jsonify from flask import make_response from sentry_sdk import capture_exception from sentry_sdk import set_tag -from SpiffWorkflow.exceptions import WorkflowException # type: ignore +from SpiffWorkflow.exceptions import WorkflowException, SpiffWorkflowException # type: ignore from SpiffWorkflow.exceptions import WorkflowTaskException from SpiffWorkflow.specs.base import TaskSpec # type: ignore from SpiffWorkflow.task import Task # type: ignore @@ -131,7 +132,7 @@ class ApiError(Exception): cls, error_code: str, message: str, - exp: WorkflowException, + exp: SpiffWorkflowException, ) -> ApiError: """Deals with workflow exceptions. @@ -140,6 +141,7 @@ class ApiError(Exception): we can with the data we have. """ if isinstance(exp, WorkflowTaskException): + # Note that WorkflowDataExceptions are also WorkflowTaskExceptions return ApiError.from_task( error_code, message, @@ -150,10 +152,10 @@ class ApiError(Exception): error_line=exp.error_line, task_trace=exp.task_trace, ) - - else: + elif isinstance(exp, WorkflowException): return ApiError.from_task_spec(error_code, message, exp.task_spec) - + else: + return ApiError("workflow_error", str(exp)) def set_user_sentry_context() -> None: """Set_user_sentry_context.""" diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py index 9063f2780..469227b8d 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py @@ -19,6 +19,7 @@ from typing import TypedDict from typing import Union from uuid import UUID +import SpiffWorkflow import dateparser import pytz from flask import current_app @@ -37,7 +38,7 @@ from SpiffWorkflow.bpmn.specs.SubWorkflowTask import SubWorkflowTask # type: ig from SpiffWorkflow.bpmn.workflow import BpmnWorkflow # type: ignore from SpiffWorkflow.dmn.parser.BpmnDmnParser import BpmnDmnParser # type: ignore from SpiffWorkflow.dmn.serializer.task_spec_converters import BusinessRuleTaskConverter # type: ignore -from SpiffWorkflow.exceptions import WorkflowException # type: ignore +from SpiffWorkflow.exceptions import WorkflowException, SpiffWorkflowException # type: ignore from SpiffWorkflow.exceptions import WorkflowTaskException from SpiffWorkflow.serializer.exceptions import MissingSpecError # type: ignore from SpiffWorkflow.spiff.serializer.task_spec_converters import BoundaryEventConverter # type: ignore @@ -1411,9 +1412,8 @@ class ProcessInstanceProcessor: if hasattr(handler, "bulk_insert_logs"): handler.bulk_insert_logs() # type: ignore db.session.commit() - - except WorkflowTaskException as we: - raise ApiError.from_workflow_exception("task_error", str(we), we) from we + except SpiffWorkflowException as swe: + raise ApiError.from_workflow_exception("task_error", str(swe), swe) from swe finally: if save: From a68c11b6f5d98b9eb94d94a97b86e4fce30eff82 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 26 Jan 2023 18:39:51 -0500 Subject: [PATCH 2/4] run_pyl --- spiffworkflow-backend/pyproject.toml | 4 ++-- .../src/spiffworkflow_backend/exceptions/api_error.py | 5 +++-- .../services/process_instance_processor.py | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/spiffworkflow-backend/pyproject.toml b/spiffworkflow-backend/pyproject.toml index da45e6848..89edd680a 100644 --- a/spiffworkflow-backend/pyproject.toml +++ b/spiffworkflow-backend/pyproject.toml @@ -28,9 +28,9 @@ flask-migrate = "*" flask-restful = "*" werkzeug = "*" # temporarily switch off main to fix CI because poetry export doesn't capture the revision if it's not here (it ignores the lock) -# SpiffWorkflow = {git = "https://github.com/sartography/SpiffWorkflow", rev = "main"} +SpiffWorkflow = {git = "https://github.com/sartography/SpiffWorkflow", rev = "main"} # SpiffWorkflow = {git = "https://github.com/sartography/SpiffWorkflow", rev = "450ef3bcd639b6bc1c115fbe35bf3f93946cb0c7"} -SpiffWorkflow = {develop = true, path = "../SpiffWorkflow" } +# SpiffWorkflow = {develop = true, path = "../SpiffWorkflow" } sentry-sdk = "^1.10" sphinx-autoapi = "^2.0" flask-bpmn = {git = "https://github.com/sartography/flask-bpmn", rev = "main"} diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/exceptions/api_error.py b/spiffworkflow-backend/src/spiffworkflow_backend/exceptions/api_error.py index 58821d0c2..5574fe912 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/exceptions/api_error.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/exceptions/api_error.py @@ -8,7 +8,6 @@ from typing import Any import flask.wrappers import sentry_sdk -from SpiffWorkflow.bpmn.exceptions import WorkflowDataException from flask import Blueprint from flask import current_app from flask import g @@ -16,7 +15,8 @@ from flask import jsonify from flask import make_response from sentry_sdk import capture_exception from sentry_sdk import set_tag -from SpiffWorkflow.exceptions import WorkflowException, SpiffWorkflowException # type: ignore +from SpiffWorkflow.exceptions import SpiffWorkflowException # type: ignore +from SpiffWorkflow.exceptions import WorkflowException from SpiffWorkflow.exceptions import WorkflowTaskException from SpiffWorkflow.specs.base import TaskSpec # type: ignore from SpiffWorkflow.task import Task # type: ignore @@ -157,6 +157,7 @@ class ApiError(Exception): else: return ApiError("workflow_error", str(exp)) + def set_user_sentry_context() -> None: """Set_user_sentry_context.""" try: diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py index 469227b8d..c63380c95 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py @@ -19,7 +19,6 @@ from typing import TypedDict from typing import Union from uuid import UUID -import SpiffWorkflow import dateparser import pytz from flask import current_app @@ -38,7 +37,8 @@ from SpiffWorkflow.bpmn.specs.SubWorkflowTask import SubWorkflowTask # type: ig from SpiffWorkflow.bpmn.workflow import BpmnWorkflow # type: ignore from SpiffWorkflow.dmn.parser.BpmnDmnParser import BpmnDmnParser # type: ignore from SpiffWorkflow.dmn.serializer.task_spec_converters import BusinessRuleTaskConverter # type: ignore -from SpiffWorkflow.exceptions import WorkflowException, SpiffWorkflowException # type: ignore +from SpiffWorkflow.exceptions import SpiffWorkflowException # type: ignore +from SpiffWorkflow.exceptions import WorkflowException from SpiffWorkflow.exceptions import WorkflowTaskException from SpiffWorkflow.serializer.exceptions import MissingSpecError # type: ignore from SpiffWorkflow.spiff.serializer.task_spec_converters import BoundaryEventConverter # type: ignore From fbf3dd788f4bc7aeb29702c61232a33ebd420c1f Mon Sep 17 00:00:00 2001 From: burnettk Date: Thu, 26 Jan 2023 21:59:02 -0500 Subject: [PATCH 3/4] update lock file in backend and arena, though that one needs pruning --- poetry.lock | 2 +- spiffworkflow-backend/poetry.lock | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/poetry.lock b/poetry.lock index 3608303e0..eddb1917b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1760,7 +1760,7 @@ lxml = "*" type = "git" url = "https://github.com/sartography/SpiffWorkflow" reference = "main" -resolved_reference = "1f51db962ccaed5810f5d0f7d76a932f056430ab" +resolved_reference = "98c6294f1240aee599cd98bcee58d121cb57b331" [[package]] name = "sqlalchemy" diff --git a/spiffworkflow-backend/poetry.lock b/spiffworkflow-backend/poetry.lock index b22d24664..6456f9572 100644 --- a/spiffworkflow-backend/poetry.lock +++ b/spiffworkflow-backend/poetry.lock @@ -1824,8 +1824,8 @@ lxml = "*" [package.source] type = "git" url = "https://github.com/sartography/SpiffWorkflow" -reference = "450ef3bcd639b6bc1c115fbe35bf3f93946cb0c7" -resolved_reference = "450ef3bcd639b6bc1c115fbe35bf3f93946cb0c7" +reference = "main" +resolved_reference = "98c6294f1240aee599cd98bcee58d121cb57b331" [[package]] name = "SQLAlchemy" @@ -2204,7 +2204,7 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools" [metadata] lock-version = "1.1" python-versions = ">=3.9,<3.12" -content-hash = "95c08ed2de5b5d047474666c9e9a5ff3e7e94e6184649c2aa6d3a961711f14b0" +content-hash = "b16e8fb0cf991bcba08c3ef1ddf205f5899c622a10c79a7f50fb55a36d53b179" [metadata.files] alabaster = [ @@ -2546,6 +2546,7 @@ greenlet = [ {file = "greenlet-2.0.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d5b0ff9878333823226d270417f24f4d06f235cb3e54d1103b71ea537a6a86ce"}, {file = "greenlet-2.0.1-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:be9e0fb2ada7e5124f5282d6381903183ecc73ea019568d6d63d33f25b2a9000"}, {file = "greenlet-2.0.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0b493db84d124805865adc587532ebad30efa68f79ad68f11b336e0a51ec86c2"}, + {file = "greenlet-2.0.1-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:0459d94f73265744fee4c2d5ec44c6f34aa8a31017e6e9de770f7bcf29710be9"}, {file = "greenlet-2.0.1-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:a20d33124935d27b80e6fdacbd34205732660e0a1d35d8b10b3328179a2b51a1"}, {file = "greenlet-2.0.1-cp37-cp37m-win32.whl", hash = "sha256:ea688d11707d30e212e0110a1aac7f7f3f542a259235d396f88be68b649e47d1"}, {file = "greenlet-2.0.1-cp37-cp37m-win_amd64.whl", hash = "sha256:afe07421c969e259e9403c3bb658968702bc3b78ec0b6fde3ae1e73440529c23"}, @@ -2554,6 +2555,7 @@ greenlet = [ {file = "greenlet-2.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:659f167f419a4609bc0516fb18ea69ed39dbb25594934bd2dd4d0401660e8a1e"}, {file = "greenlet-2.0.1-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:356e4519d4dfa766d50ecc498544b44c0249b6de66426041d7f8b751de4d6b48"}, {file = "greenlet-2.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:811e1d37d60b47cb8126e0a929b58c046251f28117cb16fcd371eed61f66b764"}, + {file = "greenlet-2.0.1-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:d38ffd0e81ba8ef347d2be0772e899c289b59ff150ebbbbe05dc61b1246eb4e0"}, {file = "greenlet-2.0.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:0109af1138afbfb8ae647e31a2b1ab030f58b21dd8528c27beaeb0093b7938a9"}, {file = "greenlet-2.0.1-cp38-cp38-win32.whl", hash = "sha256:88c8d517e78acdf7df8a2134a3c4b964415b575d2840a2746ddb1cc6175f8608"}, {file = "greenlet-2.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:d6ee1aa7ab36475035eb48c01efae87d37936a8173fc4d7b10bb02c2d75dd8f6"}, @@ -2562,6 +2564,7 @@ greenlet = [ {file = "greenlet-2.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:505138d4fa69462447a562a7c2ef723c6025ba12ac04478bc1ce2fcc279a2db5"}, {file = "greenlet-2.0.1-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:cce1e90dd302f45716a7715517c6aa0468af0bf38e814ad4eab58e88fc09f7f7"}, {file = "greenlet-2.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9e9744c657d896c7b580455e739899e492a4a452e2dd4d2b3e459f6b244a638d"}, + {file = "greenlet-2.0.1-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:662e8f7cad915ba75d8017b3e601afc01ef20deeeabf281bd00369de196d7726"}, {file = "greenlet-2.0.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:41b825d65f31e394b523c84db84f9383a2f7eefc13d987f308f4663794d2687e"}, {file = "greenlet-2.0.1-cp39-cp39-win32.whl", hash = "sha256:db38f80540083ea33bdab614a9d28bcec4b54daa5aff1668d7827a9fc769ae0a"}, {file = "greenlet-2.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:b23d2a46d53210b498e5b701a1913697671988f4bf8e10f935433f6e7c332fb6"}, @@ -2863,10 +2866,7 @@ orjson = [ {file = "orjson-3.8.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:b68a42a31f8429728183c21fb440c21de1b62e5378d0d73f280e2d894ef8942e"}, {file = "orjson-3.8.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:ff13410ddbdda5d4197a4a4c09969cb78c722a67550f0a63c02c07aadc624833"}, {file = "orjson-3.8.0-cp310-none-win_amd64.whl", hash = "sha256:2d81e6e56bbea44be0222fb53f7b255b4e7426290516771592738ca01dbd053b"}, - {file = "orjson-3.8.0-cp311-cp311-macosx_10_7_x86_64.whl", hash = "sha256:200eae21c33f1f8b02a11f5d88d76950cd6fd986d88f1afe497a8ae2627c49aa"}, - {file = "orjson-3.8.0-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:9529990f3eab54b976d327360aa1ff244a4b12cb5e4c5b3712fcdd96e8fe56d4"}, {file = "orjson-3.8.0-cp311-cp311-manylinux_2_28_x86_64.whl", hash = "sha256:e2defd9527651ad39ec20ae03c812adf47ef7662bdd6bc07dabb10888d70dc62"}, - {file = "orjson-3.8.0-cp311-none-win_amd64.whl", hash = "sha256:b21c7af0ff6228ca7105f54f0800636eb49201133e15ddb80ac20c1ce973ef07"}, {file = "orjson-3.8.0-cp37-cp37m-macosx_10_7_x86_64.whl", hash = "sha256:9e6ac22cec72d5b39035b566e4b86c74b84866f12b5b0b6541506a080fb67d6d"}, {file = "orjson-3.8.0-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:e2f4a5542f50e3d336a18cb224fc757245ca66b1fd0b70b5dd4471b8ff5f2b0e"}, {file = "orjson-3.8.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e1418feeb8b698b9224b1f024555895169d481604d5d884498c1838d7412794c"}, From 0b9c82c68d1acff3e4324cc878ef291b40c013c9 Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 3 Feb 2023 13:58:38 -0500 Subject: [PATCH 4/4] run_pyl --- .../keycloak/realm_exports/spiffworkflow-realm.json | 2 +- .../services/process_instance_processor.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spiffworkflow-backend/keycloak/realm_exports/spiffworkflow-realm.json b/spiffworkflow-backend/keycloak/realm_exports/spiffworkflow-realm.json index 722f12760..eab3bd968 100644 --- a/spiffworkflow-backend/keycloak/realm_exports/spiffworkflow-realm.json +++ b/spiffworkflow-backend/keycloak/realm_exports/spiffworkflow-realm.json @@ -3554,4 +3554,4 @@ "clientPolicies" : { "policies" : [ ] } -} \ No newline at end of file +} diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py index 1524587fb..516011157 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py @@ -43,7 +43,7 @@ from SpiffWorkflow.bpmn.workflow import BpmnWorkflow # type: ignore from SpiffWorkflow.dmn.parser.BpmnDmnParser import BpmnDmnParser # type: ignore from SpiffWorkflow.dmn.serializer.task_spec import BusinessRuleTaskConverter # type: ignore from SpiffWorkflow.exceptions import SpiffWorkflowException # type: ignore -from SpiffWorkflow.exceptions import WorkflowException # type: ignore +from SpiffWorkflow.exceptions import WorkflowException from SpiffWorkflow.exceptions import WorkflowTaskException from SpiffWorkflow.serializer.exceptions import MissingSpecError # type: ignore from SpiffWorkflow.spiff.serializer.config import SPIFF_SPEC_CONFIG # type: ignore @@ -604,7 +604,7 @@ class ProcessInstanceProcessor: ) ) except Exception as err: - raise (err) + raise err finally: spiff_logger.setLevel(original_spiff_logger_log_level) @@ -633,7 +633,7 @@ class ProcessInstanceProcessor: ) -> None: """Raise_if_no_potential_owners.""" if not potential_owner_ids: - raise (NoPotentialOwnersForTaskError(message)) + raise NoPotentialOwnersForTaskError(message) def get_potential_owner_ids_from_task( self, task: SpiffTask