Skip to content

Commit 4ce8271

Browse files
fix: project id missing
1 parent 44ad1ce commit 4ce8271

File tree

2 files changed

+28
-30
lines changed

2 files changed

+28
-30
lines changed

services/web/server/src/simcore_service_webserver/functions/_controller/_functions_rest.py

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from ...login.decorators import login_required
2424
from ...models import AuthenticatedRequestContext
2525
from ...projects import _projects_service
26+
from ...projects.models import ProjectDBGet
2627
from ...security.decorators import permission_required
2728
from ...utils_aiohttp import envelope_json_response
2829
from .. import _functions_service
@@ -88,7 +89,10 @@ async def list_functions(request: web.Request) -> web.Response:
8889
pagination_offset=query_params.offset,
8990
)
9091

91-
chunk = []
92+
chunk: list[RegisteredFunctionGet] = []
93+
projects_map: dict[str, ProjectDBGet] = (
94+
{}
95+
) # ProjectDBGet has to be renamed at some point!
9296

9397
if query_params.include_extras:
9498
project_ids = []
@@ -101,40 +105,34 @@ async def list_functions(request: web.Request) -> web.Response:
101105
request.app,
102106
project_uuids=project_ids,
103107
)
104-
projects_map = {f"{p.uuid}": p for p in projects}
105-
106-
for function in functions:
107-
if (
108-
query_params.include_extras
109-
and function.function_class == FunctionClass.PROJECT
110-
):
111-
assert isinstance(function, RegisteredProjectFunction) # nosec
112-
project = projects_map.get(f"{function.project_id}")
113-
if project:
114-
chunk.append(
115-
TypeAdapter(RegisteredProjectFunctionGet).validate_python(
116-
function.model_dump(mode="json")
117-
| {
118-
"thumbnail": project.thumbnail,
119-
"template_id": project.id,
120-
}
121-
)
122-
)
123-
else:
108+
for project in projects:
109+
projects_map[f"{project.uuid}"] = project
110+
111+
for function in functions:
112+
if (
113+
query_params.include_extras
114+
and function.function_class == FunctionClass.PROJECT
115+
):
116+
assert isinstance(function, RegisteredProjectFunction) # nosec
117+
project = projects_map.get(f"{function.project_id}")
118+
if project:
124119
chunk.append(
125-
TypeAdapter(RegisteredFunctionGet).validate_python(
120+
TypeAdapter(RegisteredProjectFunctionGet).validate_python(
126121
function.model_dump(mode="json")
122+
| {
123+
"thumbnail": (
124+
f"{project.thumbnail}" if project.thumbnail else None
125+
),
126+
"template_id": project.id,
127+
}
127128
)
128129
)
129-
else:
130-
chunk.extend(
131-
[
130+
else:
131+
chunk.append(
132132
TypeAdapter(RegisteredFunctionGet).validate_python(
133133
function.model_dump(mode="json")
134134
)
135-
for function in functions
136-
]
137-
)
135+
)
138136

139137
page = Page[RegisteredFunctionGet].model_validate(
140138
paginate_data(
@@ -188,7 +186,7 @@ async def get_function(request: web.Request) -> web.Response:
188186
registered_function.model_dump(mode="json")
189187
| {
190188
"thumbnail": project_dict.get("thumbnail", None),
191-
"template_id": project_dict.get("project_id", None),
189+
"template_id": project_dict.get("id", None),
192190
}
193191
)
194192
)

services/web/server/src/simcore_service_webserver/functions/_controller/_functions_rest_schemas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class _FunctionQueryParams(BaseModel):
1616
include_extras: bool = False
1717

1818

19-
class FunctionGetQueryParams(PageQueryParameters, _FunctionQueryParams): ...
19+
class FunctionGetQueryParams(_FunctionQueryParams): ...
2020

2121

2222
class FunctionsListQueryParams(PageQueryParameters, _FunctionQueryParams): ...

0 commit comments

Comments
 (0)