From 8b35a5f8e324ddad5e9c7c16f17be953a3a2af07 Mon Sep 17 00:00:00 2001 From: Isaac To Date: Wed, 30 Oct 2024 10:42:39 -0700 Subject: [PATCH] fix: remove `@context` key from dandiset metadata This key is not part of the `Dandiset` or `PublishedDandiset` data model, so it shouldn't be validated as part of the model. --- src/dandisets_linkml_status_tools/cli/tools.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/dandisets_linkml_status_tools/cli/tools.py b/src/dandisets_linkml_status_tools/cli/tools.py index 6bd2583..3daf6a4 100644 --- a/src/dandisets_linkml_status_tools/cli/tools.py +++ b/src/dandisets_linkml_status_tools/cli/tools.py @@ -135,6 +135,9 @@ def compile_dandiset_validation_report( is published :return: The compiled validation report + :raises KeyError: If the metadata of the given dandiset does not contain + a `"@context"` field + Note: This function should only be called in the context of a `DandiAPIClient` context manager associated with the given dandiset. """ @@ -145,6 +148,20 @@ def compile_dandiset_validation_report( raw_metadata = dandiset.get_raw_metadata() + if "@context" not in raw_metadata: + msg = ( + f"There is no '@context' key in the metadata of " + f"dandiset {dandiset_id} @ version {dandiset_version}" + ) + logger.critical(msg) + raise KeyError(msg) + + # Remove the "@context" key from the metadata. + # This key is not part of the `Dandiset` + # or `PublishedDandiset` metadata model, so it shouldn't + # be validated as part of the model. + del raw_metadata["@context"] + # === Fetch dandiset version info === dandiset_version_info = dandiset.get_version(dandiset_version) # Get dandiset version status