From 22a4a8a931279c2b12dedc71bab602c2ec311c61 Mon Sep 17 00:00:00 2001 From: Alex Ioannidis Date: Thu, 5 Dec 2024 15:28:27 +0100 Subject: [PATCH] datacite: fix funding serialization for optional award fields * Makes sure that we handle missing values for optional award fields like "title" and "number". --- .../resources/serializers/datacite/schema.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/invenio_rdm_records/resources/serializers/datacite/schema.py b/invenio_rdm_records/resources/serializers/datacite/schema.py index 82d685e41..27b65b4e7 100644 --- a/invenio_rdm_records/resources/serializers/datacite/schema.py +++ b/invenio_rdm_records/resources/serializers/datacite/schema.py @@ -16,7 +16,6 @@ from flask_resources.serializers import BaseSerializerSchema from invenio_access.permissions import system_identity from invenio_i18n import lazy_gettext as _ -from invenio_records_resources.proxies import current_service_registry from marshmallow import Schema, ValidationError, fields, missing, post_dump, validate from marshmallow_utils.fields import SanitizedUnicode from marshmallow_utils.html import strip_html @@ -617,8 +616,12 @@ def get_funding(self, obj): # award award = funding.get("award") if award: # having an award is optional - funding_ref["awardTitle"] = award.get("title", {}).get("en", missing) - funding_ref["awardNumber"] = award["number"] + award_title = award.get("title", {}).get("en") + if award_title: + funding_ref["awardTitle"] = award_title + award_number = award.get("number") + if award_number: + funding_ref["awardNumber"] = award_number identifiers = award.get("identifiers", []) if identifiers: