From 4254fde3290727b38b3434f5bcab0c0f0a56d544 Mon Sep 17 00:00:00 2001 From: Anika Churilova Date: Tue, 11 Jun 2024 16:01:41 +0200 Subject: [PATCH] errors: introduce an error for drafts not found when publish record exists * closes https://github.com/inveniosoftware/invenio-app-rdm/issues/2694 --- invenio_drafts_resources/resources/records/errors.py | 5 +++++ invenio_drafts_resources/services/records/service.py | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/invenio_drafts_resources/resources/records/errors.py b/invenio_drafts_resources/resources/records/errors.py index 86c4ccb9..3ad6a926 100644 --- a/invenio_drafts_resources/resources/records/errors.py +++ b/invenio_drafts_resources/resources/records/errors.py @@ -12,6 +12,7 @@ import json from flask_resources.errors import HTTPJSONException +from invenio_pidstore.errors import PIDDoesNotExistError class RedirectException(HTTPJSONException): @@ -42,3 +43,7 @@ def get_body(self, environ=None, scope=None): "location": self.location, } return json.dumps(body) + + +class DraftNotCreatedError(PIDDoesNotExistError): + """Draft is not created for published record error.""" diff --git a/invenio_drafts_resources/services/records/service.py b/invenio_drafts_resources/services/records/service.py index 925690fa..fcb195f2 100644 --- a/invenio_drafts_resources/services/records/service.py +++ b/invenio_drafts_resources/services/records/service.py @@ -27,6 +27,7 @@ from sqlalchemy.orm.exc import NoResultFound from werkzeug.local import LocalProxy +from ...resources.records.errors import DraftNotCreatedError from .uow import ParentRecordCommitOp @@ -205,7 +206,7 @@ def read_draft(self, identity, id_, expand=False): # with object id exists for the published record, but object # getter fails to get the draft object because only the record # object exists). - raise PIDDoesNotExistError(self.draft_cls.pid.field._pid_type, id_) + raise DraftNotCreatedError(self.draft_cls.pid.field._pid_type, id_) self.require_permission(identity, "read_draft", record=draft)