Skip to content

Commit 4b8b2b9

Browse files
committed
Generate unique operation ids for /api/jobs/{job_id}/files
Work around a bug in FastAPI (fastapi/fastapi#13175) that assigns the same operation id to both request methods GET and HEAD of the endpoint `/api/jobs/{job_id}/files` when using the `@router.api_route()` decorator with `methods=["GET", "HEAD"]` as keyword argument.
1 parent f0df4fb commit 4b8b2b9

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

client/src/api/schema/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3031,7 +3031,7 @@ export interface paths {
30313031
*
30323032
* This API method is intended only for consumption by job runners, not end users.
30333033
*/
3034-
head: operations["index_api_jobs__job_id__files_get"];
3034+
head: operations["index_api_jobs__job_id__files_head"];
30353035
patch?: never;
30363036
trace?: never;
30373037
};
@@ -31334,7 +31334,7 @@ export interface operations {
3133431334
};
3133531335
};
3133631336
};
31337-
index_api_jobs__job_id__files_get: {
31337+
index_api_jobs__job_id__files_head: {
3133831338
parameters: {
3133931339
query: {
3134031340
/** @description Path to file. */

lib/galaxy/webapps/galaxy/api/job_files.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,29 @@ class FastAPIJobFiles:
6565
# needs to include some code to handle this behavior, as tests existing before the migration to FastAPI expect HEAD
6666
# requests to work.
6767
#
68-
# @router.get( # use me when ALL endpoints have been migrated to FastAPI
69-
@router.api_route(
70-
"/api/jobs/{job_id}/files",
71-
summary="Get a file required to staging a job.",
72-
responses={
73-
200: {
74-
"description": "Contents of file.",
75-
"content": {"application/json": None, "application/octet-stream": {"example": None}},
76-
},
77-
400: {
78-
"description": (
79-
"File not found, path does not refer to a file, or input dataset(s) for job have been purged."
80-
)
81-
},
82-
},
83-
methods=["GET", "HEAD"], # remove me when ALL endpoints have been migrated to FastAPI
68+
@router.get(
69+
# simplify me (remove `_args` and `_kwargs` defined using the walrus operator) when ALL endpoints have been
70+
# migrated to FastAPI, this is a workaround for FastAPI bug https://github.com/fastapi/fastapi/issues/13175
71+
*(_args := ["/api/jobs/{job_id}/files"]),
72+
**(
73+
_kwargs := dict(
74+
summary="Get a file required to staging a job.",
75+
responses={
76+
200: {
77+
"description": "Contents of file.",
78+
"content": {"application/json": None, "application/octet-stream": {"example": None}},
79+
},
80+
400: {
81+
"description": (
82+
"File not found, path does not refer to a file, or input dataset(s) for job have been purged."
83+
)
84+
},
85+
},
86+
)
87+
),
8488
)
89+
@router.head(*_args, **_kwargs) # type: ignore[name-defined]
90+
# remove `@router.head(...)` when ALL endpoints have been migrated to FastAPI
8591
def index(
8692
self,
8793
job_id: Annotated[str, Path(description="Encoded id string of the job.")],

0 commit comments

Comments
 (0)