Skip to content

Commit 5c1e7d9

Browse files
committed
Discriminate history exports response union
The index_exports endpoint returns either JobExportHistoryArchiveListResponse or ExportTaskListResponse depending on the Accept header. Without a discriminator Pydantic walks the union left-to-right at serialization and warns "Expected JobExportHistoryArchiveListResponse" for every task-based response. Add a callable Discriminator that routes by instance type, matching the pattern used for the nested export payload union.
1 parent c116c65 commit 5c1e7d9

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

lib/galaxy/webapps/galaxy/api/histories.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
Response,
2323
status,
2424
)
25+
from pydantic import (
26+
Discriminator,
27+
Tag,
28+
)
2529
from pydantic.fields import Field
2630
from pydantic.main import BaseModel
2731

@@ -186,6 +190,19 @@ class CreateHistoryFormData(CreateHistoryPayload):
186190
]
187191

188192

193+
def _index_exports_response_discriminator(value: Any) -> str:
194+
return "tasks" if isinstance(value, ExportTaskListResponse) else "jobs"
195+
196+
197+
IndexExportsResponse = Annotated[
198+
Union[
199+
Annotated[JobExportHistoryArchiveListResponse, Tag("jobs")],
200+
Annotated[ExportTaskListResponse, Tag("tasks")],
201+
],
202+
Discriminator(_index_exports_response_discriminator),
203+
]
204+
205+
189206
@router.cbv
190207
class FastAPIHistories:
191208
service: HistoriesService = depends(HistoriesService)
@@ -551,7 +568,7 @@ def index_exports(
551568
limit: Optional[int] = LimitQueryParam,
552569
offset: Optional[int] = OffsetQueryParam,
553570
accept: IndexExportsAcceptHeader = "application/json",
554-
) -> Union[JobExportHistoryArchiveListResponse, ExportTaskListResponse]:
571+
) -> IndexExportsResponse:
555572
"""
556573
By default the legacy job-based history exports (jeha) are returned.
557574

0 commit comments

Comments
 (0)