14
14
from models_library .users import UserID
15
15
from models_library .utils .fastapi_encoders import jsonable_encoder
16
16
from pydantic import PositiveInt
17
+ from simcore_postgres_database .utils_repos import (
18
+ pass_or_acquire_connection ,
19
+ transaction_context ,
20
+ )
17
21
from sqlalchemy .dialects .postgresql .asyncpg import AsyncAdapt_asyncpg_dbapi
18
22
from sqlalchemy .ext .asyncio import AsyncConnection
19
23
from sqlalchemy .sql import or_
@@ -56,7 +60,8 @@ async def get(
56
60
57
61
:raises ComputationalRunNotFoundError: no entry found
58
62
"""
59
- async with self .db_engine .connect () as conn :
63
+
64
+ async with pass_or_acquire_connection (self .db_engine ) as conn :
60
65
result = await conn .execute (
61
66
sa .select (comp_runs )
62
67
.where (
@@ -213,7 +218,7 @@ async def list_for_user__only_latest_iterations(
213
218
)
214
219
list_query = list_query .offset (offset ).limit (limit )
215
220
216
- async with self .db_engine . connect ( ) as conn :
221
+ async with pass_or_acquire_connection ( self .db_engine ) as conn :
217
222
total_count = await conn .scalar (count_query )
218
223
219
224
items = [
@@ -238,7 +243,7 @@ async def create(
238
243
use_on_demand_clusters : bool ,
239
244
) -> CompRunsAtDB :
240
245
try :
241
- async with self .db_engine . begin ( ) as conn :
246
+ async with transaction_context ( self .db_engine ) as conn :
242
247
if iteration is None :
243
248
iteration = await self ._get_next_iteration (
244
249
conn , user_id , project_id
@@ -309,7 +314,7 @@ def _handle_foreign_key_violation(
309
314
async def update (
310
315
self , user_id : UserID , project_id : ProjectID , iteration : PositiveInt , ** values
311
316
) -> CompRunsAtDB | None :
312
- async with self .db_engine . begin ( ) as conn :
317
+ async with transaction_context ( self .db_engine ) as conn :
313
318
result = await conn .execute (
314
319
sa .update (comp_runs )
315
320
.where (
0 commit comments