From 6c2c72ef0def0359c1a84bf5df2e5a94a921460e Mon Sep 17 00:00:00 2001 From: Keith Manville Date: Thu, 26 Dec 2024 13:41:16 -0500 Subject: [PATCH] fix: errors in draft modifications commit workflow --- src/dioptra/restapi/errors.py | 2 +- src/dioptra/restapi/v1/workflows/service.py | 28 ++++++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/dioptra/restapi/errors.py b/src/dioptra/restapi/errors.py index 075f88507..ec5840ad1 100644 --- a/src/dioptra/restapi/errors.py +++ b/src/dioptra/restapi/errors.py @@ -438,7 +438,7 @@ def handle_draft_already_exists(error: DraftAlreadyExistsError): log.debug(error.to_message()) return error_result(error, http.HTTPStatus.BAD_REQUEST, {}) - @api.errorhandler(DraftAlreadyExistsError) + @api.errorhandler(DraftResourceModificationsCommitError) def handle_draft_resource_modifications_commit_error( error: DraftResourceModificationsCommitError, ): diff --git a/src/dioptra/restapi/v1/workflows/service.py b/src/dioptra/restapi/v1/workflows/service.py index 6e609bc0c..4aeb4da44 100644 --- a/src/dioptra/restapi/v1/workflows/service.py +++ b/src/dioptra/restapi/v1/workflows/service.py @@ -125,36 +125,40 @@ def commit_draft(self, draft_id: int, **kwargs) -> dict: log=log, ) else: # the draft contains modifications to an existing resource - resource = views.get_latest_resource_snapshot( - draft.resource_type, draft.resource_id + snapshot = views.get_latest_resource_snapshot( + draft.resource_type, draft.payload["resource_id"] ) - if resource is None: + if snapshot is None: raise EntityDoesNotExistError( - draft.resource_type, resource_id=draft.resource_id + draft.resource_type, resource_id=draft.payload["resource_id"] ) # if the underlying resource was modified since the draft was created, # raise an error with the information necessary to reconcile the draft. - if draft.resource_snapshot_id != resource.latest_snapshot_id: + if ( + draft.payload["resource_snapshot_id"] + != snapshot.resource.latest_snapshot_id + ): prev_snapshot = views.get_resource_snapshot( - draft.resource_type, draft.resource_snapshot_id + draft.resource_type, draft.payload["resource_snapshot_id"] ) if prev_snapshot is None: raise EntityDoesNotExistError( - draft.resource_type, snapshot_id=draft.resource_snapshot_id + draft.resource_type, + snapshot_id=draft.payload["resource_snapshot_id"], ) curr_snapshot = views.get_resource_snapshot( - draft.resource_type, resource.latest_snapshot_id + draft.resource_type, snapshot.resource.latest_snapshot_id ) if curr_snapshot is None: raise EntityDoesNotExistError( - draft.resource_type, resource_id=draft.resource_id + draft.resource_type, resource_id=draft.payload["resource_id"] ) raise DraftResourceModificationsCommitError( resource_type=draft.resource_type, - resource_id=draft.resource_id, + resource_id=draft.payload["resource_id"], draft=utils.build_resource( draft.resource_type, {draft.resource_type: draft} ), @@ -166,8 +170,8 @@ def commit_draft(self, draft_id: int, **kwargs) -> dict: ), ) - resource_dict = self._resource_service.modify( - resource_id=draft.resource_id, + resource_dict = self._resource_id_service.modify( + resource_id=draft.payload["resource_id"], resource_type=draft.resource_type, resource_data=draft.payload["resource_data"], group_id=draft.group_id,