|
5 | 5 | from typing import Dict, List, Optional |
6 | 6 | from uuid import UUID, uuid4 |
7 | 7 |
|
8 | | -from pydantic import Field, root_validator, validate_model |
| 8 | +from pydantic import Field, root_validator, validate_model, validator |
9 | 9 |
|
10 | 10 | from aind_data_schema.base import AindCoreModel |
11 | 11 | from aind_data_schema.data_description import DataDescription |
@@ -37,7 +37,7 @@ class Metadata(AindCoreModel): |
37 | 37 | """The records in the Data Asset Collection needs to contain certain fields |
38 | 38 | to easily query and index the data.""" |
39 | 39 |
|
40 | | - schema_version: str = Field("0.0.4", description="schema version", title="Version", const=True) |
| 40 | + schema_version: str = Field("0.0.5", description="schema version", title="Version", const=True) |
41 | 41 |
|
42 | 42 | id: UUID = Field( |
43 | 43 | default_factory=uuid4, |
@@ -96,6 +96,25 @@ class Metadata(AindCoreModel): |
96 | 96 | None, title="Instrument", description="Instrument, which is a collection of devices" |
97 | 97 | ) |
98 | 98 |
|
| 99 | + @validator( |
| 100 | + "subject", |
| 101 | + "data_description", |
| 102 | + "procedures", |
| 103 | + "session", |
| 104 | + "rig", |
| 105 | + "processing", |
| 106 | + "acquisition", |
| 107 | + "instrument", |
| 108 | + pre=True, |
| 109 | + ) |
| 110 | + def validate_core_fields(cls, value, values, field): |
| 111 | + """Don't automatically raise errors if the core models are invalid""" |
| 112 | + if isinstance(value, dict): |
| 113 | + core_model = field.type_.construct(**value) |
| 114 | + else: |
| 115 | + core_model = value |
| 116 | + return core_model |
| 117 | + |
99 | 118 | @root_validator(pre=False) |
100 | 119 | def validate_metadata(cls, values): |
101 | 120 | """Validator for metadata""" |
|
0 commit comments