Skip to content

Commit bca70f4

Browse files
committed
use helpers
1 parent 8f6a629 commit bca70f4

File tree

1 file changed

+9
-4
lines changed
  • services/director-v2/src/simcore_service_director_v2/modules/db/repositories

1 file changed

+9
-4
lines changed

services/director-v2/src/simcore_service_director_v2/modules/db/repositories/comp_runs.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
from models_library.users import UserID
1515
from models_library.utils.fastapi_encoders import jsonable_encoder
1616
from pydantic import PositiveInt
17+
from simcore_postgres_database.utils_repos import (
18+
pass_or_acquire_connection,
19+
transaction_context,
20+
)
1721
from sqlalchemy.dialects.postgresql.asyncpg import AsyncAdapt_asyncpg_dbapi
1822
from sqlalchemy.ext.asyncio import AsyncConnection
1923
from sqlalchemy.sql import or_
@@ -56,7 +60,8 @@ async def get(
5660
5761
:raises ComputationalRunNotFoundError: no entry found
5862
"""
59-
async with self.db_engine.connect() as conn:
63+
64+
async with pass_or_acquire_connection(self.db_engine) as conn:
6065
result = await conn.execute(
6166
sa.select(comp_runs)
6267
.where(
@@ -213,7 +218,7 @@ async def list_for_user__only_latest_iterations(
213218
)
214219
list_query = list_query.offset(offset).limit(limit)
215220

216-
async with self.db_engine.connect() as conn:
221+
async with pass_or_acquire_connection(self.db_engine) as conn:
217222
total_count = await conn.scalar(count_query)
218223

219224
items = [
@@ -238,7 +243,7 @@ async def create(
238243
use_on_demand_clusters: bool,
239244
) -> CompRunsAtDB:
240245
try:
241-
async with self.db_engine.begin() as conn:
246+
async with transaction_context(self.db_engine) as conn:
242247
if iteration is None:
243248
iteration = await self._get_next_iteration(
244249
conn, user_id, project_id
@@ -309,7 +314,7 @@ def _handle_foreign_key_violation(
309314
async def update(
310315
self, user_id: UserID, project_id: ProjectID, iteration: PositiveInt, **values
311316
) -> CompRunsAtDB | None:
312-
async with self.db_engine.begin() as conn:
317+
async with transaction_context(self.db_engine) as conn:
313318
result = await conn.execute(
314319
sa.update(comp_runs)
315320
.where(

0 commit comments

Comments
 (0)