From fba82afcc187db13e4b85bcd7b1f5ce05edf8750 Mon Sep 17 00:00:00 2001 From: jbirddog <100367399+jbirddog@users.noreply.github.com> Date: Wed, 23 Nov 2022 15:49:43 -0500 Subject: [PATCH 1/2] Fix for updating xero token in the background (#60) --- .../src/spiffworkflow_backend/services/secret_service.py | 8 +++++++- .../services/service_task_service.py | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/secret_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/secret_service.py index 41ee22b2..e4dee491 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/secret_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/secret_service.py @@ -65,7 +65,7 @@ class SecretService: def update_secret( key: str, value: str, - user_id: int, + user_id: Optional[int] = None, create_if_not_exists: Optional[bool] = False, ) -> None: """Does this pass pre commit?""" @@ -79,6 +79,12 @@ class SecretService: db.session.rollback() raise e elif create_if_not_exists: + if user_id is None: + raise ApiError( + error_code="update_secret_error_no_user_id", + message=f"Cannot update secret with key: {key}. Missing user id.", + status_code=404, + ) SecretService.add_secret(key=key, value=value, user_id=user_id) else: raise ApiError( diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/service_task_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/service_task_service.py index 97ce1495..15e25a75 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/service_task_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/service_task_service.py @@ -8,6 +8,7 @@ from flask import g from spiffworkflow_backend.services.file_system_service import FileSystemService from spiffworkflow_backend.services.secret_service import SecretService +from spiffworkflow_backend.services.user_service import UserService class ConnectorProxyError(Exception): @@ -65,7 +66,8 @@ class ServiceTaskDelegate: secret_key = parsed_response["auth"] refreshed_token_set = json.dumps(parsed_response["refreshed_token_set"]) - SecretService().update_secret(secret_key, refreshed_token_set, g.user.id) + user_id = g.user.id if UserService.has_user() else None + SecretService().update_secret(secret_key, refreshed_token_set, user_id) return json.dumps(parsed_response["api_response"]) From d9a708847c21db159081a912c1ac32872ea13ad1 Mon Sep 17 00:00:00 2001 From: jbirddog <100367399+jbirddog@users.noreply.github.com> Date: Wed, 23 Nov 2022 15:50:02 -0500 Subject: [PATCH 2/2] Fix the postgres job (#61) --- .../src/spiffworkflow_backend/routes/process_api_blueprint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py index fdc172e9..4a894ba6 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py @@ -922,7 +922,7 @@ def process_instance_list( ) process_instances = ( - process_instance_query.distinct() + process_instance_query.group_by(ProcessInstanceModel.id) .order_by( ProcessInstanceModel.start_in_seconds.desc(), ProcessInstanceModel.id.desc() # type: ignore )