diff --git a/swh/deposit/api/deposit_update.py b/swh/deposit/api/deposit_update.py --- a/swh/deposit/api/deposit_update.py +++ b/swh/deposit/api/deposit_update.py @@ -3,6 +3,7 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information +from datetime import datetime, timezone from typing import Any, Dict, Optional, Tuple from rest_framework import status @@ -200,6 +201,7 @@ # Write to the metadata storage (and the deposit backend) # no ingestion triggered + date_now = datetime.now(tz=timezone.utc) deposit = Deposit.objects.get(pk=deposit_id) assert deposit.status == DEPOSIT_STATUS_LOAD_SUCCESS @@ -277,6 +279,28 @@ self.storage_metadata.metadata_fetcher_add([metadata_fetcher]) self.storage_metadata.raw_extrinsic_metadata_add([metadata_object]) + # ensure that new extrinsic metadata sent is stored in the metadata storage + page_result = self.storage_metadata.raw_extrinsic_metadata_get( + MetadataTargetType.DIRECTORY, + deposit_swhid, + metadata_authority, + after=date_now, + ) + found: bool = False + + # one page result iteration should be enough since we pass the date (which is + # around now) as the minimal boundary for the lookup + for extrinsic_metadata in page_result.results: + if ( + extrinsic_metadata.format == "sword-v2-atom-codemeta" + and extrinsic_metadata.metadata == metadata_object.metadata + ): + found = True + break + + if not found: + raise ValueError("Failure to save the extrinsic metadata storage.") + return { "deposit_id": deposit_id, "deposit_date": deposit_request.date,