Skip to content

Commit 583fdf6

Browse files
committed
refactor
1 parent 34b90db commit 583fdf6

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

fastapi_jsonapi/data_layers/filtering/sqlalchemy.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from fastapi_jsonapi.data_layers.shared import create_filters_or_sorts
2222
from fastapi_jsonapi.data_typing import TypeModel, TypeSchema
2323
from fastapi_jsonapi.exceptions import InvalidFilters, InvalidType
24+
from fastapi_jsonapi.exceptions.json_api import HTTPException
2425
from fastapi_jsonapi.schema import get_model_field, get_relationships
2526
from fastapi_jsonapi.splitter import SPLIT_REL
2627
from fastapi_jsonapi.utils.sqla import get_related_model_cls
@@ -119,7 +120,10 @@ def create_filter(self, schema_field: ModelField, model_column, operator, value)
119120
errors.append(str(ex))
120121

121122
if clear_value is cast_failed:
122-
raise InvalidType(detail=f"Can't cast filter value `{value}` to user type. {', '.join(errors)}")
123+
raise InvalidType(
124+
detail=f"Can't cast filter value `{value}` to user type.",
125+
errors=[HTTPException(status_code=InvalidType.status_code, detail=str(err)) for err in errors],
126+
)
123127

124128
# Если None, при этом поле обязательное (среди типов в аннотации нет None, то кидаем ошибку)
125129
if clear_value is None and not any(not i_f.required for i_f in fields):

tests/test_api/test_api_sqla_with_includes.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,8 +2420,15 @@ class Config:
24202420
)
24212421

24222422
assert exc_info.value.as_dict == {
2423-
"detail": "Can't cast filter value `typing.Any` to user type. Cast failed",
2424-
"source": {"pointer": ""},
2423+
"detail": "Can't cast filter value `typing.Any` to user type.",
2424+
"meta": [
2425+
{
2426+
"detail": "Cast failed",
2427+
"source": {"pointer": ""},
2428+
"status_code": status.HTTP_409_CONFLICT,
2429+
"title": "Conflict",
2430+
},
2431+
],
24252432
"status_code": status.HTTP_409_CONFLICT,
24262433
"title": "Invalid type.",
24272434
}

0 commit comments

Comments
 (0)