diff --git a/cds_migrator_kit/rdm/records/load/entities/ep_migration_entry_load.py b/cds_migrator_kit/rdm/records/load/entities/ep_migration_entry_load.py index 700d4416..8a3908e0 100644 --- a/cds_migrator_kit/rdm/records/load/entities/ep_migration_entry_load.py +++ b/cds_migrator_kit/rdm/records/load/entities/ep_migration_entry_load.py @@ -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) + self.request_load_cls(restricted_entry).load( restricted_records, self.create_inclusion_request, uow ) diff --git a/cds_migrator_kit/rdm/records/load/entities/ep_split.py b/cds_migrator_kit/rdm/records/load/entities/ep_split.py index cf5b8895..e4b444ad 100644 --- a/cds_migrator_kit/rdm/records/load/entities/ep_split.py +++ b/cds_migrator_kit/rdm/records/load/entities/ep_split.py @@ -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": kept.append(id_entry) continue - identifier = id_entry.get("identifier", "") if not identifier.startswith(EP_APPROVAL_REPORT_NUMBER_PREFIX): kept.append(id_entry) continue diff --git a/cds_migrator_kit/rdm/records/transform/entities/record.py b/cds_migrator_kit/rdm/records/transform/entities/record.py index 5058ed30..599fd94f 100644 --- a/cds_migrator_kit/rdm/records/transform/entities/record.py +++ b/cds_migrator_kit/rdm/records/transform/entities/record.py @@ -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} def _custom_fields(self, dojson_entry, raw_dump_entry): diff --git a/tests/cds-rdm/test_ep_approval_entry.py b/tests/cds-rdm/test_ep_approval_entry.py index 483fc232..3cb97593 100644 --- a/tests/cds-rdm/test_ep_approval_entry.py +++ b/tests/cds-rdm/test_ep_approval_entry.py @@ -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(