diff --git a/internal/dto/repository/exception.py b/internal/dto/repository/exception.py index e69de29b..27c82a2d 100644 --- a/internal/dto/repository/exception.py +++ b/internal/dto/repository/exception.py @@ -0,0 +1,3 @@ +class ModelNotFoundException(Exception): + def __init__(self, message: str): + super().__init__(message) diff --git a/internal/repository/relational/crud.py b/internal/repository/relational/crud.py index d97b03f1..65cb0fc4 100644 --- a/internal/repository/relational/crud.py +++ b/internal/repository/relational/crud.py @@ -10,6 +10,7 @@ BaseResponseSchema, ) from internal.infrastructure.data_storage import Context +from internal.dto.repository.exception import ModelNotFoundException class CRUD[ @@ -70,6 +71,11 @@ def update( ) -> ResponseSchema: db_model_instance = self._find(find_schema, context) + if not db_model_instance: + raise ModelNotFoundException( + "When updating data, the required row was not found in the database." + ) + update_schema_dict = update_schema.model_dump() fields_to_update_if_none = ( fields_to_update_if_none if fields_to_update_if_none else set()