Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,15 @@ def _load_split(self, entry: MigrationEntry, recid):
recid, restricted_records
)

# 2. Create and approve EP approval request
approval_request_load.create(restricted_record_state, uow=uow)

# Parent access grants + community-inclusion request for
# the restricted half.
# Parent access grants + communities before EP approval request
# (needs parent.communities.default for referee group lookup).
self.parent_load_cls(
restricted_entry, self.migration_logger, restricted_record_state
).load(published_record=restricted_records[-1], uow=uow)

# 2. Create and approve EP approval request
approval_request_load.create(restricted_record_state, uow=uow)

Comment on lines +152 to +160

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ApprovalRequestLoad needs parent.communities.default to pick the EP referee group. So it should be set before creating the request

self.request_load_cls(restricted_entry).load(
restricted_records, self.create_inclusion_request, uow
)
Expand Down
9 changes: 7 additions & 2 deletions cds_migrator_kit/rdm/records/load/entities/ep_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,15 @@ def identifiers(self, identifiers):
kept = []
removed = []
for id_entry in identifiers:
if id_entry.get("scheme") != "cdsrn":
scheme = id_entry.get("scheme")
identifier = id_entry.get("identifier", "")
# apprn belongs only on the public record.
if scheme == "apprn":
removed.append(identifier)
continue
elif scheme != "cdsrn":
Comment on lines +326 to +332

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed apprn from restricted record

kept.append(id_entry)
continue
identifier = id_entry.get("identifier", "")
if not identifier.startswith(EP_APPROVAL_REPORT_NUMBER_PREFIX):
kept.append(id_entry)
continue
Expand Down
2 changes: 2 additions & 0 deletions cds_migrator_kit/rdm/records/transform/entities/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ def _metadata(self, dojson_entry, raw_dump_entry):
# metadata["resource_type"]; see mappers/registry.py.
for mapper in METADATA_MAPPERS:
metadata[mapper.id] = mapper.map_value(ctx)
# Consume the key even if the value is later dropped.
dojson_entry.pop(mapper.id, None)
return {k: v for k, v in metadata.items() if v}
Comment on lines +192 to 194

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's empty field we're having Unassigned metadata key error.

  • {k: v if v} drops it from record.body["metadata"]
  • Key still sits in dojson_entry
  • Check thinks it’s unassigned

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry it is not clear to me why do we need this change....

@zubeydecivelek zubeydecivelek Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty metadata (e.g. related_identifiers=[]) is filtered out or dropped in metadata, but without popping it stays in dojson_entry. _check_forgotten_keys then flags it as unassigned and throws Unassigned metadata key error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also change the _check_forgotten_keys method so it skips the empty values


def _custom_fields(self, dojson_entry, raw_dump_entry):
Expand Down
16 changes: 16 additions & 0 deletions tests/cds-rdm/test_ep_approval_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,22 @@ def test_restricted_removes_matching_cern_ep_rn(self, app):

assert APPROVED_REPORT_NUMBER not in cdsrn_values

def test_restricted_removes_apprn(self, app):
identifiers = [
{"identifier": RECID, "scheme": "cds"},
{"scheme": "apprn", "identifier": APPROVED_REPORT_NUMBER},
{"scheme": "cdsrn", "identifier": DRAFT_REPORT_NUMBER},
]
entry = _make_entry(_versions_with_epphapp(), identifiers=identifiers)
result = RestrictedEntry(
entry, _make_approval_request(), _make_migration_logger()
).build()

assert not any(
i["scheme"] == "apprn"
for i in result["record"].body["metadata"]["identifiers"]
)

def test_restricted_keeps_draft_report_number(self, app):
entry = _make_entry(_versions_with_epphapp())
result = RestrictedEntry(
Expand Down
Loading