Skip to content

Commit 853f248

Browse files
committed
pids: fix register/update serialization
1 parent 0f08d2a commit 853f248

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

invenio_rdm_records/services/pids/service.py

+14
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,20 @@ def register_or_update(
193193
if f"{link_prefix}_{scheme}" in links:
194194
url = links[f"{link_prefix}_{scheme}"]
195195

196+
# NOTE: This is not the best place to do this, since we shouldn't be aware of
197+
# the fact that the record has a `RelationsField``. However, without
198+
# dereferencing, we're not able to serialize the record properly for
199+
# registration/updates (e.g. for the DataCite DOIs).
200+
# Some possible alternatives:
201+
#
202+
# - Fetch the record from the service, so that it is already in a
203+
# serializable dereferenced state.
204+
# - Bake-in the dereferencing in the serializer, though this would
205+
# be not very consistent regarding the architecture layers.
206+
relations = getattr(pid_record, "relations", None)
207+
if relations:
208+
relations.dereference()
209+
196210
if pid.is_registered():
197211
self.require_permission(identity, "pid_update", record=record)
198212
pid_manager.update(pid_record, scheme, url=url)

invenio_rdm_records/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __getattr__(self, name):
7171

7272
objs = super().__getattribute__("_objs")
7373
for o in objs:
74-
if getattr(o, name):
74+
if getattr(o, name, None):
7575
return getattr(o, name)
7676
raise AttributeError()
7777

0 commit comments

Comments
 (0)