Skip to content

Commit 16db6a4

Browse files
kysrpexmvdbeek
authored andcommitted
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 056a283 commit 16db6a4

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
@@ -3096,7 +3096,7 @@ export interface paths {
30963096
*
30973097
* This API method is intended only for consumption by job runners, not end users.
30983098
*/
3099-
head: operations["index_api_jobs__job_id__files_get"];
3099+
head: operations["index_api_jobs__job_id__files_head"];
31003100
patch?: never;
31013101
trace?: never;
31023102
};
@@ -31858,7 +31858,7 @@ export interface operations {
3185831858
};
3185931859
};
3186031860
};
31861-
index_api_jobs__job_id__files_get: {
31861+
index_api_jobs__job_id__files_head: {
3186231862
parameters: {
3186331863
query: {
3186431864
/** @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)