fix(chalice): transform array-source to single value for sessions-filters (#1943)

This commit is contained in:
Kraiem Taha Yassine 2024-03-12 12:28:57 +01:00 committed by GitHub
parent 7b0027e3bd
commit ee6b22b579
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -658,6 +658,18 @@ class SessionSearchFilterSchema(BaseModel):
_transform = model_validator(mode='before')(transform_old_filter_type)
_single_to_list_values = field_validator('value', mode='before')(single_to_list)
@model_validator(mode='before')
def _transform_data(cls, values):
if values.get("source") is not None:
if isinstance(values["source"], list):
if len(values["source"]) == 0:
values["source"] = None
elif len(values["source"]) == 1:
values["source"] = values["source"][0]
else:
raise ValueError(f"Unsupported multi-values source")
return values
@model_validator(mode='after')
def filter_validator(cls, values):
if values.type == FilterType.metadata: