Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: add Marc21ValidationError #176

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions invenio_records_marc21/services/record/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# This file is part of Invenio.
#
# Copyright (C) 2022 Graz University of Technology.
# Copyright (C) 2022-2023 Graz University of Technology.
#
# Invenio-Records-Marc21 is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
Expand All @@ -16,6 +16,7 @@

from invenio_search import RecordsSearch
from invenio_search.engine import dsl
from marshmallow.exceptions import ValidationError

from .types import DOI, ACNumber, DuplicateRecordError

Expand All @@ -42,20 +43,25 @@ def create_record(service, data, file_paths, identity, do_publish=True):
"""Create the record."""
draft = service.create(data=data, identity=identity, files=True)

for file_path in file_paths:
add_file_to_record(
marcid=draft.id,
file_path=file_path,
file_service=service.draft_files,
identity=identity,
)

if do_publish:
# to prevent the race condition bug.
# see https://github.com/inveniosoftware/invenio-rdm-records/issues/809
time.sleep(0.5)

return service.publish(id_=draft.id, identity=identity)
try:
for file_path in file_paths:
add_file_to_record(
marcid=draft.id,
file_path=file_path,
file_service=service.draft_files,
identity=identity,
)

if do_publish:
# to prevent the race condition bug.
# see https://github.com/inveniosoftware/invenio-rdm-records/issues/809
time.sleep(0.5)

return service.publish(id_=draft.id, identity=identity)

except (FileNotFoundError, ValidationError) as error:
service.delete_draft(id_=draft.id, identity=identity)
raise error

return draft

Expand Down