Skip to content

Commit 54028fb

Browse files
fix: move project_exists
1 parent 398866c commit 54028fb

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

packages/postgres-database/src/simcore_postgres_database/utils_projects.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from sqlalchemy.ext.asyncio import AsyncConnection
88

99
from .models.projects import projects
10-
from .utils_repos import transaction_context
10+
from .utils_repos import pass_or_acquire_connection, transaction_context
1111

1212

1313
class DBBaseProjectError(OsparcErrorMixin, Exception):
@@ -22,6 +22,23 @@ class ProjectsRepo:
2222
def __init__(self, engine):
2323
self.engine = engine
2424

25+
async def exists(
26+
self,
27+
project_uuid: uuid.UUID,
28+
*,
29+
connection: AsyncConnection | None = None,
30+
) -> bool:
31+
async with pass_or_acquire_connection(self.engine, connection) as conn:
32+
return (
33+
await conn.scalar(
34+
sa.select(1)
35+
.select_from(projects)
36+
.where(projects.c.uuid == project_uuid)
37+
.limit(1)
38+
)
39+
is not None
40+
)
41+
2542
async def get_project_last_change_date(
2643
self,
2744
project_uuid: uuid.UUID,

services/storage/src/simcore_service_storage/modules/db/projects.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,6 @@ async def list_valid_projects_in(
3333
with suppress(ValidationError):
3434
yield ProjectAtDB.model_validate(row)
3535

36-
async def project_exists(
37-
self,
38-
*,
39-
connection: AsyncConnection | None = None,
40-
project_uuid: ProjectID,
41-
) -> bool:
42-
async with pass_or_acquire_connection(self.db_engine, connection) as conn:
43-
return bool(
44-
await conn.scalar(
45-
sa.select(sa.func.count())
46-
.select_from(projects)
47-
.where(projects.c.uuid == f"{project_uuid}")
48-
)
49-
== 1
50-
)
51-
5236
async def get_project_id_and_node_id_to_names_map(
5337
self,
5438
*,

services/storage/src/simcore_service_storage/simcore_s3_dsm.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from servicelib.logging_utils import log_context
4242
from servicelib.progress_bar import ProgressBarData
4343
from servicelib.utils import ensure_ends_with, limited_gather
44+
from simcore_postgres_database.utils_projects import ProjectsRepo
4445
from simcore_postgres_database.utils_repos import transaction_context
4546
from sqlalchemy.ext.asyncio import AsyncEngine
4647

@@ -792,9 +793,9 @@ async def deep_copy_project_simcore_s3(
792793
task_progress.description = "Checking study access rights..."
793794

794795
for prj_uuid in [src_project_uuid, dst_project_uuid]:
795-
if not await ProjectRepository.instance(
796-
get_db_engine(self.app)
797-
).project_exists(project_uuid=prj_uuid):
796+
if not await ProjectsRepo(get_db_engine(self.app)).exists(
797+
project_uuid=prj_uuid
798+
):
798799
raise ProjectNotFoundError(project_id=prj_uuid)
799800
source_access_rights = await AccessLayerRepository.instance(
800801
get_db_engine(self.app)

0 commit comments

Comments
 (0)