Skip to content

Commit 10b0814

Browse files
committed
fix(infrastructure): fix postgres io details (#62)
1 parent 0d24ac4 commit 10b0814

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/ttt/infrastructure/adapters/games.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,18 @@ async def current_user_game(self, user_id: int, /) -> Game | None:
2828
return table_game.entity()
2929

3030
async def not_locked_game_with_id(self, game_id: UUID, /) -> Game | None:
31+
lock_stmt = (
32+
select(1)
33+
.select_from(TableGame)
34+
.where(TableGame.id == game_id)
35+
.with_for_update()
36+
)
3137
stmt = (
3238
select(TableGame)
3339
.where(TableGame.id == game_id)
34-
.with_for_update()
3540
)
41+
42+
await self._session.execute(lock_stmt)
3643
table_game = await self._session.scalar(stmt)
44+
3745
return None if table_game is None else table_game.entity()

src/ttt/infrastructure/adapters/transaction.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async def __aexit__(
3838
return
3939

4040
with reraise_serialization_error():
41-
if error is None:
41+
if error is None and transaction.is_active:
4242
await transaction.commit()
4343
else:
4444
await transaction.rollback()
@@ -71,7 +71,7 @@ async def __aexit__(
7171
if transaction is None:
7272
return
7373

74-
if error is None:
74+
if error is None and transaction.is_active:
7575
await transaction.commit()
7676
else:
7777
await transaction.rollback()
@@ -102,7 +102,7 @@ async def __aexit__(
102102
if transaction is None:
103103
return
104104

105-
if error is None:
105+
if error is None and transaction.is_active:
106106
await transaction.commit()
107107
else:
108108
await transaction.rollback()

0 commit comments

Comments
 (0)