Skip to content

Commit 9fb4f34

Browse files
Replaces assert with explicit validation
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 103f388 commit 9fb4f34

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/repositories/interface.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,12 @@ def get_model_repo(cls, model: ApiBaseModel) -> Self:
215215
@repository_exception_handler
216216
async def insert(self, data: dict):
217217
collection = self.get_collection()
218-
assert self.model.model_validate(data)
218+
try:
219+
self.model.model_validate(data)
220+
except ValidationError as e:
221+
raise HTTPException(status_code=422, detail=str(e))
219222
result = await collection.insert_one(data)
220223
return str(result.inserted_id)
221-
222224
@repository_exception_handler
223225
async def update_by_id(self, data: dict, *, data_id: str):
224226
collection = self.get_collection()

0 commit comments

Comments
 (0)