Skip to content

Commit 35da134

Browse files
feat: sqlalchemy repository error if rowcount is not found
1 parent 4962d2a commit 35da134

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

app/common/infrastructure/base_sqlalchemy_repository.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,14 @@ def _raise_not_deleted(self) -> t.NoReturn:
221221
def _get_row_count(self, result: sa.Result) -> int:
222222
# NOTE: in runtime, the Result is a CursorResult which has this prop
223223
# but the type stubs do not reflect this
224-
return t.cast(sa.CursorResult[t.Any], result).rowcount
224+
match result:
225+
case sa.CursorResult(rowcount=row_count):
226+
return row_count
227+
case _:
228+
msg = (
229+
"Can't get result row count: "
230+
f"expected result to be a CursorResult, got {type(result)} instead. "
231+
"This could indicate a breaking change with sqlalchemy, "
232+
"review sqlalchemy repository implementation."
233+
)
234+
raise repository_errors.RepositoryError(msg)

0 commit comments

Comments
 (0)