Skip to content

Commit 1ccb606

Browse files
authored
Fix python client wrt function job status 🐛 (#8309)
1 parent d7ee297 commit 1ccb606

File tree

3 files changed

+120
-106
lines changed

3 files changed

+120
-106
lines changed

services/api-server/openapi.json

Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -5567,7 +5567,7 @@
55675567
"content": {
55685568
"application/json": {
55695569
"schema": {
5570-
"$ref": "#/components/schemas/Page_Union_Annotated_Union_RegisteredProjectFunctionJobWithStatus__RegisteredPythonCodeFunctionJobWithStatus__RegisteredSolverFunctionJobWithStatus___FieldInfo_annotation_NoneType__required_True__discriminator__function_class_____Annotated_Union_RegisteredProjectFunctionJob__RegisteredPythonCodeFunctionJob__RegisteredSolverFunctionJob___FieldInfo_annotation_NoneType__required_True__discriminator__function_class_____"
5570+
"$ref": "#/components/schemas/PageRegisteredFunctionJobWithorWithoutStatus"
55715571
}
55725572
}
55735573
}
@@ -9946,29 +9946,54 @@
99469946
],
99479947
"title": "OnePage[StudyPort]"
99489948
},
9949-
"Page_Annotated_Union_RegisteredProjectFunctionJob__RegisteredPythonCodeFunctionJob__RegisteredSolverFunctionJob___FieldInfo_annotation_NoneType__required_True__discriminator__function_class____": {
9949+
"PageRegisteredFunctionJobWithorWithoutStatus": {
99509950
"properties": {
99519951
"items": {
99529952
"items": {
9953-
"oneOf": [
9954-
{
9955-
"$ref": "#/components/schemas/RegisteredProjectFunctionJob"
9956-
},
9953+
"anyOf": [
99579954
{
9958-
"$ref": "#/components/schemas/RegisteredPythonCodeFunctionJob"
9955+
"oneOf": [
9956+
{
9957+
"$ref": "#/components/schemas/RegisteredProjectFunctionJobWithStatus"
9958+
},
9959+
{
9960+
"$ref": "#/components/schemas/RegisteredPythonCodeFunctionJobWithStatus"
9961+
},
9962+
{
9963+
"$ref": "#/components/schemas/RegisteredSolverFunctionJobWithStatus"
9964+
}
9965+
],
9966+
"discriminator": {
9967+
"propertyName": "function_class",
9968+
"mapping": {
9969+
"PROJECT": "#/components/schemas/RegisteredProjectFunctionJobWithStatus",
9970+
"PYTHON_CODE": "#/components/schemas/RegisteredPythonCodeFunctionJobWithStatus",
9971+
"SOLVER": "#/components/schemas/RegisteredSolverFunctionJobWithStatus"
9972+
}
9973+
}
99599974
},
99609975
{
9961-
"$ref": "#/components/schemas/RegisteredSolverFunctionJob"
9962-
}
9963-
],
9964-
"discriminator": {
9965-
"propertyName": "function_class",
9966-
"mapping": {
9967-
"PROJECT": "#/components/schemas/RegisteredProjectFunctionJob",
9968-
"PYTHON_CODE": "#/components/schemas/RegisteredPythonCodeFunctionJob",
9969-
"SOLVER": "#/components/schemas/RegisteredSolverFunctionJob"
9976+
"oneOf": [
9977+
{
9978+
"$ref": "#/components/schemas/RegisteredProjectFunctionJob"
9979+
},
9980+
{
9981+
"$ref": "#/components/schemas/RegisteredPythonCodeFunctionJob"
9982+
},
9983+
{
9984+
"$ref": "#/components/schemas/RegisteredSolverFunctionJob"
9985+
}
9986+
],
9987+
"discriminator": {
9988+
"propertyName": "function_class",
9989+
"mapping": {
9990+
"PROJECT": "#/components/schemas/RegisteredProjectFunctionJob",
9991+
"PYTHON_CODE": "#/components/schemas/RegisteredPythonCodeFunctionJob",
9992+
"SOLVER": "#/components/schemas/RegisteredSolverFunctionJob"
9993+
}
9994+
}
99709995
}
9971-
}
9996+
]
99729997
},
99739998
"type": "array",
99749999
"title": "Items"
@@ -10021,29 +10046,29 @@
1002110046
"offset",
1002210047
"links"
1002310048
],
10024-
"title": "Page[Annotated[Union[RegisteredProjectFunctionJob, RegisteredPythonCodeFunctionJob, RegisteredSolverFunctionJob], FieldInfo(annotation=NoneType, required=True, discriminator='function_class')]]"
10049+
"title": "PageRegisteredFunctionJobWithorWithoutStatus"
1002510050
},
10026-
"Page_Annotated_Union_RegisteredProjectFunction__RegisteredPythonCodeFunction__RegisteredSolverFunction___FieldInfo_annotation_NoneType__required_True__discriminator__function_class____": {
10051+
"Page_Annotated_Union_RegisteredProjectFunctionJob__RegisteredPythonCodeFunctionJob__RegisteredSolverFunctionJob___FieldInfo_annotation_NoneType__required_True__discriminator__function_class____": {
1002710052
"properties": {
1002810053
"items": {
1002910054
"items": {
1003010055
"oneOf": [
1003110056
{
10032-
"$ref": "#/components/schemas/RegisteredProjectFunction"
10057+
"$ref": "#/components/schemas/RegisteredProjectFunctionJob"
1003310058
},
1003410059
{
10035-
"$ref": "#/components/schemas/RegisteredPythonCodeFunction"
10060+
"$ref": "#/components/schemas/RegisteredPythonCodeFunctionJob"
1003610061
},
1003710062
{
10038-
"$ref": "#/components/schemas/RegisteredSolverFunction"
10063+
"$ref": "#/components/schemas/RegisteredSolverFunctionJob"
1003910064
}
1004010065
],
1004110066
"discriminator": {
1004210067
"propertyName": "function_class",
1004310068
"mapping": {
10044-
"PROJECT": "#/components/schemas/RegisteredProjectFunction",
10045-
"PYTHON_CODE": "#/components/schemas/RegisteredPythonCodeFunction",
10046-
"SOLVER": "#/components/schemas/RegisteredSolverFunction"
10069+
"PROJECT": "#/components/schemas/RegisteredProjectFunctionJob",
10070+
"PYTHON_CODE": "#/components/schemas/RegisteredPythonCodeFunctionJob",
10071+
"SOLVER": "#/components/schemas/RegisteredSolverFunctionJob"
1004710072
}
1004810073
}
1004910074
},
@@ -10098,13 +10123,31 @@
1009810123
"offset",
1009910124
"links"
1010010125
],
10101-
"title": "Page[Annotated[Union[RegisteredProjectFunction, RegisteredPythonCodeFunction, RegisteredSolverFunction], FieldInfo(annotation=NoneType, required=True, discriminator='function_class')]]"
10126+
"title": "Page[Annotated[Union[RegisteredProjectFunctionJob, RegisteredPythonCodeFunctionJob, RegisteredSolverFunctionJob], FieldInfo(annotation=NoneType, required=True, discriminator='function_class')]]"
1010210127
},
10103-
"Page_File_": {
10128+
"Page_Annotated_Union_RegisteredProjectFunction__RegisteredPythonCodeFunction__RegisteredSolverFunction___FieldInfo_annotation_NoneType__required_True__discriminator__function_class____": {
1010410129
"properties": {
1010510130
"items": {
1010610131
"items": {
10107-
"$ref": "#/components/schemas/File"
10132+
"oneOf": [
10133+
{
10134+
"$ref": "#/components/schemas/RegisteredProjectFunction"
10135+
},
10136+
{
10137+
"$ref": "#/components/schemas/RegisteredPythonCodeFunction"
10138+
},
10139+
{
10140+
"$ref": "#/components/schemas/RegisteredSolverFunction"
10141+
}
10142+
],
10143+
"discriminator": {
10144+
"propertyName": "function_class",
10145+
"mapping": {
10146+
"PROJECT": "#/components/schemas/RegisteredProjectFunction",
10147+
"PYTHON_CODE": "#/components/schemas/RegisteredPythonCodeFunction",
10148+
"SOLVER": "#/components/schemas/RegisteredSolverFunction"
10149+
}
10150+
}
1010810151
},
1010910152
"type": "array",
1011010153
"title": "Items"
@@ -10157,13 +10200,13 @@
1015710200
"offset",
1015810201
"links"
1015910202
],
10160-
"title": "Page[File]"
10203+
"title": "Page[Annotated[Union[RegisteredProjectFunction, RegisteredPythonCodeFunction, RegisteredSolverFunction], FieldInfo(annotation=NoneType, required=True, discriminator='function_class')]]"
1016110204
},
10162-
"Page_Job_": {
10205+
"Page_File_": {
1016310206
"properties": {
1016410207
"items": {
1016510208
"items": {
10166-
"$ref": "#/components/schemas/Job"
10209+
"$ref": "#/components/schemas/File"
1016710210
},
1016810211
"type": "array",
1016910212
"title": "Items"
@@ -10216,13 +10259,13 @@
1021610259
"offset",
1021710260
"links"
1021810261
],
10219-
"title": "Page[Job]"
10262+
"title": "Page[File]"
1022010263
},
10221-
"Page_LicensedItemGet_": {
10264+
"Page_Job_": {
1022210265
"properties": {
1022310266
"items": {
1022410267
"items": {
10225-
"$ref": "#/components/schemas/LicensedItemGet"
10268+
"$ref": "#/components/schemas/Job"
1022610269
},
1022710270
"type": "array",
1022810271
"title": "Items"
@@ -10275,13 +10318,13 @@
1027510318
"offset",
1027610319
"links"
1027710320
],
10278-
"title": "Page[LicensedItemGet]"
10321+
"title": "Page[Job]"
1027910322
},
10280-
"Page_RegisteredFunctionJobCollection_": {
10323+
"Page_LicensedItemGet_": {
1028110324
"properties": {
1028210325
"items": {
1028310326
"items": {
10284-
"$ref": "#/components/schemas/RegisteredFunctionJobCollection"
10327+
"$ref": "#/components/schemas/LicensedItemGet"
1028510328
},
1028610329
"type": "array",
1028710330
"title": "Items"
@@ -10334,13 +10377,13 @@
1033410377
"offset",
1033510378
"links"
1033610379
],
10337-
"title": "Page[RegisteredFunctionJobCollection]"
10380+
"title": "Page[LicensedItemGet]"
1033810381
},
10339-
"Page_Study_": {
10382+
"Page_RegisteredFunctionJobCollection_": {
1034010383
"properties": {
1034110384
"items": {
1034210385
"items": {
10343-
"$ref": "#/components/schemas/Study"
10386+
"$ref": "#/components/schemas/RegisteredFunctionJobCollection"
1034410387
},
1034510388
"type": "array",
1034610389
"title": "Items"
@@ -10393,56 +10436,13 @@
1039310436
"offset",
1039410437
"links"
1039510438
],
10396-
"title": "Page[Study]"
10439+
"title": "Page[RegisteredFunctionJobCollection]"
1039710440
},
10398-
"Page_Union_Annotated_Union_RegisteredProjectFunctionJobWithStatus__RegisteredPythonCodeFunctionJobWithStatus__RegisteredSolverFunctionJobWithStatus___FieldInfo_annotation_NoneType__required_True__discriminator__function_class_____Annotated_Union_RegisteredProjectFunctionJob__RegisteredPythonCodeFunctionJob__RegisteredSolverFunctionJob___FieldInfo_annotation_NoneType__required_True__discriminator__function_class_____": {
10441+
"Page_Study_": {
1039910442
"properties": {
1040010443
"items": {
1040110444
"items": {
10402-
"anyOf": [
10403-
{
10404-
"oneOf": [
10405-
{
10406-
"$ref": "#/components/schemas/RegisteredProjectFunctionJobWithStatus"
10407-
},
10408-
{
10409-
"$ref": "#/components/schemas/RegisteredPythonCodeFunctionJobWithStatus"
10410-
},
10411-
{
10412-
"$ref": "#/components/schemas/RegisteredSolverFunctionJobWithStatus"
10413-
}
10414-
],
10415-
"discriminator": {
10416-
"propertyName": "function_class",
10417-
"mapping": {
10418-
"PROJECT": "#/components/schemas/RegisteredProjectFunctionJobWithStatus",
10419-
"PYTHON_CODE": "#/components/schemas/RegisteredPythonCodeFunctionJobWithStatus",
10420-
"SOLVER": "#/components/schemas/RegisteredSolverFunctionJobWithStatus"
10421-
}
10422-
}
10423-
},
10424-
{
10425-
"oneOf": [
10426-
{
10427-
"$ref": "#/components/schemas/RegisteredProjectFunctionJob"
10428-
},
10429-
{
10430-
"$ref": "#/components/schemas/RegisteredPythonCodeFunctionJob"
10431-
},
10432-
{
10433-
"$ref": "#/components/schemas/RegisteredSolverFunctionJob"
10434-
}
10435-
],
10436-
"discriminator": {
10437-
"propertyName": "function_class",
10438-
"mapping": {
10439-
"PROJECT": "#/components/schemas/RegisteredProjectFunctionJob",
10440-
"PYTHON_CODE": "#/components/schemas/RegisteredPythonCodeFunctionJob",
10441-
"SOLVER": "#/components/schemas/RegisteredSolverFunctionJob"
10442-
}
10443-
}
10444-
}
10445-
]
10445+
"$ref": "#/components/schemas/Study"
1044610446
},
1044710447
"type": "array",
1044810448
"title": "Items"
@@ -10495,7 +10495,7 @@
1049510495
"offset",
1049610496
"links"
1049710497
],
10498-
"title": "Page[Union[Annotated[Union[RegisteredProjectFunctionJobWithStatus, RegisteredPythonCodeFunctionJobWithStatus, RegisteredSolverFunctionJobWithStatus], FieldInfo(annotation=NoneType, required=True, discriminator='function_class')], Annotated[Union[RegisteredProjectFunctionJob, RegisteredPythonCodeFunctionJob, RegisteredSolverFunctionJob], FieldInfo(annotation=NoneType, required=True, discriminator='function_class')]]]"
10498+
"title": "Page[Study]"
1049910499
},
1050010500
"PricingPlanClassification": {
1050110501
"type": "string",

services/api-server/src/simcore_service_api_server/api/routes/function_jobs_routes.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from collections.abc import Sequence
21
from logging import getLogger
32
from typing import Annotated, Final
43

@@ -14,7 +13,7 @@
1413
FunctionOutputs,
1514
RegisteredFunctionJob,
1615
)
17-
from models_library.functions import RegisteredFunction, RegisteredFunctionJobWithStatus
16+
from models_library.functions import RegisteredFunction
1817
from models_library.functions_errors import (
1918
UnsupportedFunctionClassError,
2019
UnsupportedFunctionFunctionJobClassCombinationError,
@@ -31,7 +30,8 @@
3130
from ..._service_functions import FunctionService
3231
from ..._service_jobs import JobService
3332
from ...exceptions.function_errors import FunctionJobProjectMissingError
34-
from ...models.pagination import Page, PaginationParams
33+
from ...models.domain.functions import PageRegisteredFunctionJobWithorWithoutStatus
34+
from ...models.pagination import PaginationParams
3535
from ...models.schemas.errors import ErrorGet
3636
from ...models.schemas.functions_filters import FunctionJobsListFilters
3737
from ...services_rpc.wb_api_server import WbApiRpcClient
@@ -116,9 +116,7 @@
116116

117117
@function_job_router.get(
118118
"",
119-
response_model=Page[
120-
RegisteredFunctionJobWithStatus | RegisteredFunctionJob
121-
], # left-right order is important here
119+
response_model=PageRegisteredFunctionJobWithorWithoutStatus,
122120
description=create_route_description(
123121
base="List function jobs", changelog=CHANGE_LOGS["list_function_jobs"]
124122
),
@@ -138,11 +136,8 @@ async def list_function_jobs(
138136
bool, Query(description="Include job status in response")
139137
] = False,
140138
):
141-
function_jobs_list: Sequence[
142-
RegisteredFunctionJobWithStatus | RegisteredFunctionJob
143-
] = []
144139
if include_status:
145-
function_jobs_list, meta = (
140+
function_jobs_list_ws, meta = (
146141
await function_job_service.list_function_jobs_with_status(
147142
pagination_offset=page_params.offset,
148143
pagination_limit=page_params.limit,
@@ -153,7 +148,7 @@ async def list_function_jobs(
153148
)
154149
# the code below should ideally be in the service layer, but this can only be done if the
155150
# celery status resolution is done in the service layer too
156-
for function_job_wso in function_jobs_list:
151+
for function_job_wso in function_jobs_list_ws:
157152
if (
158153
function_job_wso.status.status
159154
not in (
@@ -183,15 +178,21 @@ async def list_function_jobs(
183178
async_pg_engine=async_pg_engine,
184179
)
185180
)
186-
else:
187-
function_jobs_list, meta = await function_job_service.list_function_jobs(
188-
pagination_offset=page_params.offset,
189-
pagination_limit=page_params.limit,
190-
filter_by_function_job_ids=filters.function_job_ids,
191-
filter_by_function_job_collection_id=filters.function_job_collection_id,
192-
filter_by_function_id=filters.function_id,
181+
182+
return create_page(
183+
function_jobs_list_ws,
184+
total=meta.total,
185+
params=page_params,
193186
)
194187

188+
function_jobs_list, meta = await function_job_service.list_function_jobs(
189+
pagination_offset=page_params.offset,
190+
pagination_limit=page_params.limit,
191+
filter_by_function_job_ids=filters.function_job_ids,
192+
filter_by_function_job_collection_id=filters.function_job_collection_id,
193+
filter_by_function_id=filters.function_id,
194+
)
195+
195196
return create_page(
196197
function_jobs_list,
197198
total=meta.total,
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1-
from models_library.functions import FunctionJobID
1+
from models_library.functions import (
2+
FunctionJobID,
3+
RegisteredFunctionJob,
4+
RegisteredFunctionJobWithStatus,
5+
)
26
from pydantic import BaseModel
37

8+
from ...models.pagination import Page
49
from ...models.schemas.jobs import JobInputs
510

611

712
class PreRegisteredFunctionJobData(BaseModel):
813
function_job_id: FunctionJobID
914
job_inputs: JobInputs
15+
16+
17+
class PageRegisteredFunctionJobWithorWithoutStatus(
18+
Page[RegisteredFunctionJobWithStatus | RegisteredFunctionJob] # order is important
19+
):
20+
# This class is created specifically to provide a name for this in openapi.json.
21+
# When using an alias the python-client generates too long file name
22+
pass

0 commit comments

Comments
 (0)