Skip to content

Commit 688e56d

Browse files
fix behaviour
1 parent 34ff63e commit 688e56d

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,17 @@ async def _aggregate_data_to_projects_from_other_sources(
9999
async def _legacy_convert_db_projects_to_api_projects(
100100
app: web.Application,
101101
db,
102-
db_projects: list,
102+
db_projects: list[dict[str, Any]],
103103
) -> list[dict]:
104104
"""
105105
Converts db schema projects to API schema (legacy postprocessing).
106106
"""
107107
api_projects: list[dict] = []
108108
for db_prj in db_projects:
109-
db_prj_dict = db_prj.model_dump()
109+
db_prj_dict = db_prj
110110
db_prj_dict.pop("product_name", None)
111-
db_prj_dict["tags"] = await db.get_tags_by_project(project_id=f"{db_prj.id}")
112-
user_email = await get_user_email_legacy(app, db_prj.prj_owner)
111+
db_prj_dict["tags"] = await db.get_tags_by_project(project_id=f"{db_prj['id']}")
112+
user_email = await get_user_email_legacy(app, db_prj["prj_owner"])
113113
api_projects.append(convert_to_schema_names(db_prj_dict, user_email))
114114
return api_projects
115115

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ async def list_projects_dicts( # pylint: disable=too-many-arguments,too-many-st
588588
limit: int | None = None,
589589
# order
590590
order_by: OrderBy = DEFAULT_ORDER_BY,
591-
) -> tuple[list[ProjectListAtDB], int]:
591+
) -> tuple[list[dict[str, Any]], int]:
592592
async with self.engine.acquire() as conn:
593593
user_groups_proxy: list[RowProxy] = await self._list_user_groups(
594594
conn, user_id
@@ -671,12 +671,15 @@ async def list_projects_dicts( # pylint: disable=too-many-arguments,too-many-st
671671
projects.c.id,
672672
)
673673

674-
prjs_output = [
674+
prjs_output = []
675+
async for row in conn.execute(combined_query.offset(offset).limit(limit)):
676+
# NOTE: Historically, projects were returned as a dictionary. I have created a model that
677+
# validates the DB row, but this model includes some default values inside the Workbench Node model.
678+
# Therefore, if we use this model, it will return those default values, which is not backward-compatible
679+
# with the frontend. The frontend would need to check and adapt how it handles default values in
680+
# Workbench nodes, which are currently not returned if not set in the DB.
675681
ProjectListAtDB.model_validate(row)
676-
async for row in conn.execute(
677-
combined_query.offset(offset).limit(limit)
678-
)
679-
]
682+
prjs_output.append(dict(row.items()))
680683

681684
return (
682685
prjs_output,

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@
88
import sqlalchemy as sa
99
from aiopg.sa.connection import SAConnection
1010
from aiopg.sa.result import RowProxy
11-
from models_library.projects import ProjectID, ProjectTemplateType
11+
from models_library.projects import ProjectID, ProjectType
1212
from models_library.projects_nodes import Node
1313
from models_library.projects_nodes_io import NodeIDStr
1414
from models_library.utils.change_case import camel_to_snake, snake_to_camel
1515
from pydantic import ValidationError
1616
from simcore_postgres_database.models.project_to_groups import project_to_groups
17-
from simcore_postgres_database.webserver_models import ProjectType, projects
17+
from simcore_postgres_database.webserver_models import (
18+
ProjectTemplateType as ProjectTemplateTypeDB,
19+
)
20+
from simcore_postgres_database.webserver_models import ProjectType as ProjectTypeDB
21+
from simcore_postgres_database.webserver_models import (
22+
projects,
23+
)
1824
from sqlalchemy.dialects.postgresql import insert as pg_insert
1925

2026
from ..db.models import GroupType, groups, projects_tags, user_to_groups, users
@@ -88,9 +94,9 @@ def convert_to_schema_names(
8894
if col_name == "prj_owner":
8995
# this entry has to be converted to the owner e-mail address
9096
converted_value = user_email
91-
if col_name == "type" and isinstance(col_value, ProjectType):
97+
if col_name == "type" and isinstance(col_value, ProjectTypeDB):
9298
converted_value = col_value.value
93-
if col_name == "template_type" and isinstance(col_value, ProjectTemplateType):
99+
if col_name == "template_type" and isinstance(col_value, ProjectTemplateTypeDB):
94100
converted_value = col_value.value
95101

96102
if col_name in SCHEMA_NON_NULL_KEYS and col_value is None:

0 commit comments

Comments
 (0)