[docs]@model_validator(mode="after")defvalidate_contract(self)->ManifestField:ifself.rangeisnotNoneand(self.minisnotNoneorself.maxisnotNone):raiseValueError("range cannot be combined with min or max")ifself.type=="enum"andself.allowedValuesisNoneandself.enumRefisNone:raiseValueError("enum fields must define allowedValues or enumRef")ifself.typein{"date","dateTime"}andnotself.format:raiseValueError(f"{self.type} fields must define format")ifself.typein{"date","dateTime"}andself.format:if"%"notinself.format:raiseValueError(f"{self.type} format must use strftime directives like %Y or %Y-%m-%d")sample=datetime(2024,3,13,12,30,45,tzinfo=UTC)try:rendered=sample.strftime(self.format)datetime.strptime(rendered,self.format)exceptValueErrorasexc:raiseValueError(f"{self.type} format must be a valid strftime format")fromexcifself.type=="dateTime"andself.formatand"%z"notinself.format:raiseValueError("dateTime formats must include timezone information via %z")returnself
[docs]@model_validator(mode="after")defvalidate_shape(self)->DatasetManifest:if"ID"notinself.categoryor"name"notinself.category:raiseValueError("category must define ID and name")if"ID"notinself.collectionor"name"notinself.collection:raiseValueError("collection must define ID and name")ifself.datasetKind==DatasetKind.TABULARandnotself.datasetTables:raiseValueError("tabular manifests must define datasetTables")returnself