Skip to content

Commit

Permalink
add back in validator
Browse files Browse the repository at this point in the history
  • Loading branch information
thingscouldbeworse committed Nov 4, 2024
1 parent 81e96eb commit a0ef7a1
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/fideslang/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
HttpUrl,
PositiveInt,
SerializeAsAny,
ValidationInfo,
field_validator,
model_validator,
)
Expand All @@ -31,6 +32,7 @@
is_deprecated_if_replaced,
matching_parent_key,
no_self_reference,
parse_data_type_string,
sort_list_objects_by_name,
unique_items_in_list,
valid_data_type,
Expand Down Expand Up @@ -468,6 +470,30 @@ def valid_meta(cls, meta_values: Optional[FidesMeta]) -> Optional[FidesMeta]:
"The 'return_all_elements' attribute can only be specified on array fields."
)
return meta_values

@model_validator(mode="after")
def validate_object_fields(
self,
_: ValidationInfo,
) -> DatasetField:
"""Two validation checks for object fields:
- If there are sub-fields specified, type should be either empty or 'object'
"""
if self.fields:
breakpoint()
fields = self.fields
declared_data_type = None
field_name: str = self.name

if self.fides_meta:
declared_data_type = self.fides_meta.data_type

if fields and declared_data_type:
data_type, _ = parse_data_type_string(declared_data_type)
if data_type != "object":
raise ValueError(
f"The data type '{data_type}' on field '{field_name}' is not compatible with specified sub-fields. Convert to an 'object' field."
)


# this is required for the recursive reference in the pydantic model:
Expand Down

0 comments on commit a0ef7a1

Please sign in to comment.