Skip to content

Commit

Permalink
fix: validate metadata of published dandiset against `PublishedDandis…
Browse files Browse the repository at this point in the history
…et` in Pydantic validation
  • Loading branch information
candleindark committed Oct 30, 2024
1 parent 888641e commit 5d0a4f4
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/dandisets_linkml_status_tools/cli/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import Any, NamedTuple, Optional

from dandi.dandiapi import RemoteDandiset
from dandischema.models import Dandiset, PublishedDandiset
from linkml.validator import Validator
from linkml.validator.plugins import JsonschemaValidationPlugin, ValidationPlugin
from linkml.validator.report import ValidationResult
Expand Down Expand Up @@ -141,6 +142,14 @@ def compile_dandiset_validation_report(
Note: This function should only be called in the context of a `DandiAPIClient`
context manager associated with the given dandiset.
"""
# Determine validation targets
if is_dandiset_published:
pydantic_validation_target = PublishedDandiset # Specified as a Pydantic model
linkml_validation_target = "PublishedDandiset" # Specified as a LinkML class
else:
pydantic_validation_target = Dandiset # Specified as a Pydantic model
linkml_validation_target = "Dandiset" # Specified as a LinkML class

dandi_model_linkml_validator = DandiModelLinkmlValidator()

dandiset_id = dandiset.identifier
Expand Down Expand Up @@ -170,7 +179,9 @@ def compile_dandiset_validation_report(
dandiset_version_modified = dandiset_version_info.modified

# Validate the raw metadata using the Pydantic model
pydantic_validation_errs = pydantic_validate(raw_metadata)
pydantic_validation_errs = pydantic_validate(
raw_metadata, pydantic_validation_target
)
if pydantic_validation_errs != "[]":
logger.info(
"Captured Pydantic validation errors for dandiset %s @ %s",
Expand All @@ -180,7 +191,7 @@ def compile_dandiset_validation_report(

# Validate the raw metadata using the LinkML schema
linkml_validation_errs = dandi_model_linkml_validator.validate(
raw_metadata, "PublishedDandiset" if is_dandiset_published else "Dandiset"
raw_metadata, linkml_validation_target
)
if linkml_validation_errs:
logger.info(
Expand Down

0 comments on commit 5d0a4f4

Please sign in to comment.