From 38a5a764aa69b155c5c5ea0d28ee850f5d8adb8f Mon Sep 17 00:00:00 2001 From: Felix Uellendall Date: Fri, 18 Oct 2024 16:11:02 +0200 Subject: [PATCH] Add missing commit to update --- fastcrud/crud/fast_crud.py | 2 ++ tests/sqlalchemy/crud/test_update.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/fastcrud/crud/fast_crud.py b/fastcrud/crud/fast_crud.py index d3c876b..158e8e0 100644 --- a/fastcrud/crud/fast_crud.py +++ b/fastcrud/crud/fast_crud.py @@ -2222,6 +2222,8 @@ async def update( if return_columns: stmt = stmt.returning(*[column(name) for name in return_columns]) db_row = await db.execute(stmt) + if commit: + await db.commit() if allow_multiple: return self._as_multi_response( db_row, diff --git a/tests/sqlalchemy/crud/test_update.py b/tests/sqlalchemy/crud/test_update.py index c265370..b917f44 100644 --- a/tests/sqlalchemy/crud/test_update.py +++ b/tests/sqlalchemy/crud/test_update.py @@ -276,3 +276,7 @@ async def test_update_with_returning( ) assert updated_record == expected_result + + # Rollback the current transaction to see if the record was actually committed + await async_session.rollback() + assert await crud.count(async_session, name="Updated Name") == 1