Skip to content

Commit 6fecdcc

Browse files
committed
by_alias since Page is strict
1 parent 93391eb commit 6fecdcc

File tree

5 files changed

+43
-32
lines changed

5 files changed

+43
-32
lines changed

packages/models-library/tests/test_project_nodes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def test_create_minimal_node(minimal_node_data_sample: dict[str, Any]):
2525
# a nice way to see how the simplest node looks like
2626
assert node.inputs == {}
2727
assert node.outputs == {}
28+
assert node.state is not None
2829
assert node.state.current_status == RunningState.NOT_STARTED
2930
assert node.state.modified is True
3031
assert node.state.dependencies == set()

services/web/server/src/simcore_service_webserver/projects/_crud_api_create.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,9 @@ async def create_project( # pylint: disable=too-many-arguments,too-many-branche
440440
for gid, access in workspace.access_rights.items()
441441
}
442442

443-
data = ProjectGet.from_domain_model(new_project).data(**RESPONSE_MODEL_POLICY)
443+
data = ProjectGet.from_domain_model(new_project).model_dump(
444+
**RESPONSE_MODEL_POLICY
445+
)
444446

445447
raise web.HTTPCreated(
446448
text=json_dumps({"data": data}),

services/web/server/src/simcore_service_webserver/projects/_crud_handlers.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,10 @@ async def list_projects(request: web.Request):
214214

215215
page = Page[ProjectListItem].model_validate(
216216
paginate_data(
217-
chunk=[ProjectListItem.from_domain_model(prj) for prj in projects],
217+
chunk=[
218+
ProjectListItem.from_domain_model(prj).model_dump(by_alias=True)
219+
for prj in projects
220+
],
218221
request_url=request.url,
219222
total=total_number_of_projects,
220223
limit=query_params.limit,
@@ -256,7 +259,10 @@ async def list_projects_full_search(request: web.Request):
256259

257260
page = Page[ProjectListItem].model_validate(
258261
paginate_data(
259-
chunk=[ProjectListItem.from_domain_model(prj) for prj in projects],
262+
chunk=[
263+
ProjectListItem.from_domain_model(prj).model_dump(by_alias=True)
264+
for prj in projects
265+
],
260266
request_url=request.url,
261267
total=total_number_of_projects,
262268
limit=query_params.limit,

services/web/server/src/simcore_service_webserver/projects/_projects_db.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,15 @@ async def get_trashed_by_primary_gid(
5656
*,
5757
projects_uuid: ProjectID,
5858
) -> GroupID | None:
59-
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
60-
query = (
61-
sa.select(
62-
users.c.primary_gid.label("trashed_by_primary_gid"),
63-
)
64-
.select_from(projects.outerjoin(users, projects.c.trashed_by == users.c.id))
65-
.where(projects.c.uuid == projects_uuid)
59+
query = (
60+
sa.select(
61+
users.c.primary_gid.label("trashed_by_primary_gid"),
6662
)
63+
.select_from(projects.outerjoin(users, projects.c.trashed_by == users.c.id))
64+
.where(projects.c.uuid == projects_uuid)
65+
)
66+
67+
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
6768
result = await conn.stream(query)
6869
row = await result.first()
6970
return row.trashed_by_primary_gid if row else None
@@ -75,24 +76,27 @@ async def batch_get_trashed_by_primary_gid(
7576
*,
7677
projects_uuids: list[ProjectID],
7778
) -> list[GroupID | None]:
79+
"""Batch version of get_trashed_by_primary_gid
80+
81+
Returns:
82+
values of trashed_by_primary_gid in the SAME ORDER as projects_uuids
7883
"""
79-
Batch version of get_trashed_by_primary_gid preserving ORDER of projects_uuids
80-
"""
81-
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
82-
query = (
83-
sa.select(
84-
users.c.primary_gid.label("trashed_by_primary_gid"),
85-
)
86-
.select_from(projects.outerjoin(users, projects.c.trashed_by == users.c.id))
87-
.where(projects.c.uuid.in_(projects_uuids))
88-
).order_by(
89-
# Preserves the order of projects_uuids
90-
sa.case(
91-
*[
92-
(projects.c.uuid == uuid, index)
93-
for index, uuid in enumerate(projects_uuids)
94-
]
95-
)
84+
projects_uuids_str = [f"{uuid}" for uuid in projects_uuids]
85+
query = (
86+
sa.select(
87+
users.c.primary_gid.label("trashed_by_primary_gid"),
9688
)
89+
.select_from(projects.outerjoin(users, projects.c.trashed_by == users.c.id))
90+
.where(projects.c.uuid.in_(projects_uuids_str))
91+
).order_by(
92+
# Preserves the order of projects_uuids
93+
sa.case(
94+
*[
95+
(projects.c.uuid == uuid, index)
96+
for index, uuid in enumerate(projects_uuids_str)
97+
]
98+
)
99+
)
100+
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
97101
result = await conn.stream(query)
98102
return [row.trashed_by_primary_gid async for row in result]

services/web/server/src/simcore_service_webserver/projects/projects_service.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,10 @@ async def get_project_for_user(
180180
include_trashed_by_primary_gid: bool = False,
181181
check_permissions: str = "read",
182182
) -> ProjectDict:
183-
"""Returns a VALID project accessible to user
183+
"""
184+
Raises:
185+
ProjectNotFoundError: _description_
184186
185-
:raises ProjectNotFoundError: if no match found
186-
:
187-
:return: schema-compliant project data
188-
:rtype: Dict
189187
"""
190188
db = ProjectDBAPI.get_from_app_context(app)
191189

0 commit comments

Comments
 (0)