diff --git a/src/ttt/infrastructure/adapters/games.py b/src/ttt/infrastructure/adapters/games.py index d31e4ad..67a9fcd 100644 --- a/src/ttt/infrastructure/adapters/games.py +++ b/src/ttt/infrastructure/adapters/games.py @@ -20,7 +20,9 @@ async def game_with_game_location( join_condition = (TableUser.id == game_location_user_id) & ( TableUser.game_location_game_id == TableGame.id ) - stmt = select(TableGame).join(TableUser, join_condition) + stmt = ( + select(TableGame).join(TableUser, join_condition).with_for_update() + ) table_game = await self._session.scalar(stmt) diff --git a/src/ttt/infrastructure/adapters/users.py b/src/ttt/infrastructure/adapters/users.py index 5079439..08e0835 100644 --- a/src/ttt/infrastructure/adapters/users.py +++ b/src/ttt/infrastructure/adapters/users.py @@ -19,7 +19,7 @@ async def contains_user_with_id( id_: int, /, ) -> bool: - stmt = select(exists(1).where(TableUser.id == id_)) + stmt = select(exists(1).where(TableUser.id == id_)).with_for_update() return bool(await self._session.execute(stmt)) @@ -50,6 +50,7 @@ async def users_with_ids( return tuple(users) async def user_with_id(self, id_: int, /) -> User | None: - table_user = await self._session.get(TableUser, id_) + stmt = select(TableUser).where(TableUser.id == id_).with_for_update() + table_user = await self._session.scalar(stmt) return None if table_user is None else table_user.entity()