Skip to content

Commit

Permalink
add validator and test
Browse files Browse the repository at this point in the history
  • Loading branch information
ekorman committed Aug 22, 2024
1 parent b97c9dc commit 750d0b5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions api/tests/unit-tests/schemas/test_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,20 @@ def test_EvaluationResponse():
created_at=datetime.now(),
meta={},
)

# test validation for meta
er = schemas.EvaluationResponse(
id=1,
dataset_names=["ds"],
model_name="test",
filters=schemas.Filter(),
parameters=schemas.EvaluationParameters(
task_type=enums.TaskType.CLASSIFICATION,
),
status=enums.EvaluationStatus.DONE,
metrics=[],
confusion_matrices=[],
created_at=datetime.now(),
meta=None,
)
assert er.meta == {}
6 changes: 6 additions & 0 deletions api/valor_api/schemas/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,9 @@ class EvaluationResponse(BaseModel):
model_config = ConfigDict(
extra="allow", protected_namespaces=("protected_",)
)

# make sure that `meta` is a dictionary
@field_validator("meta")
@classmethod
def null_to_empty_dict(cls, v):
return v or {}

0 comments on commit 750d0b5

Please sign in to comment.