Skip to content

Commit d17002d

Browse files
committed
Accept path and job_key both as query and form parameters for POST requests to /api/jobs/{job_id}/files
Pulsar formats the `path` and `job_key` parameters as query parameters when submitting POST requests to `/api/jobs/{job_id}/files`. However, many Galaxy tests format them as form parameters. The only way to keep the endpoint working as it should (as it worked before the migration to FastAPI) is to accept both query and form parameters.
1 parent 4b8b2b9 commit d17002d

File tree

2 files changed

+63
-15
lines changed

2 files changed

+63
-15
lines changed

client/src/api/schema/schema.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6682,15 +6682,15 @@ export interface components {
66826682
*/
66836683
file?: string;
66846684
/**
6685-
* Job Key
6685+
* Job Key Form
66866686
* @description A key used to authenticate this request as acting on behalf or a job runner for the specified job.
66876687
*/
6688-
job_key: string;
6688+
job_key_form?: string | null;
66896689
/**
6690-
* Path
6690+
* Path Form
66916691
* @description Path to file to create.
66926692
*/
6693-
path: string;
6693+
path_form?: string | null;
66946694
/** Session Id */
66956695
session_id?: string;
66966696
};
@@ -31288,7 +31288,12 @@ export interface operations {
3128831288
};
3128931289
create_api_jobs__job_id__files_post: {
3129031290
parameters: {
31291-
query?: never;
31291+
query?: {
31292+
/** @description Path to file to create. */
31293+
path?: string | null;
31294+
/** @description A key used to authenticate this request as acting on behalf or a job runner for the specified job. */
31295+
job_key?: string | null;
31296+
};
3129231297
header?: {
3129331298
/** @description The user ID that will be used to effectively make this API call. Only admins and designated users can make API calls on behalf of other users. */
3129431299
"run-as"?: string | null;
@@ -31299,7 +31304,7 @@ export interface operations {
3129931304
};
3130031305
cookie?: never;
3130131306
};
31302-
requestBody: {
31307+
requestBody?: {
3130331308
content: {
3130431309
"multipart/form-data": components["schemas"]["Body_create_api_jobs__job_id__files_post"];
3130531310
};

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

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
Form,
1919
Path,
2020
Query,
21+
Request,
2122
UploadFile,
2223
)
24+
from fastapi.params import Depends
2325
from typing_extensions import Annotated
2426

2527
from galaxy import (
@@ -48,6 +50,54 @@
4850
)
4951

5052

53+
def path_query_or_form(
54+
request: Request,
55+
path_query: Annotated[Optional[str], Query(alias="path", description="Path to file to create.")] = None,
56+
path_form: Annotated[Optional[str], Form(alias="path", description="Path to file to create.")] = None,
57+
):
58+
"""
59+
Accept `path` parameter both in query and form format.
60+
61+
This method does not force the client to provide the parameter, it could simply not submit the parameter in either
62+
format. To force the client to provide the parameter, coerce the output of the method to a string, i.e.
63+
`path: str = Depends(path_query_or_form)` so that FastAPI responds with status code 500 when the parameter is not
64+
provided.
65+
"""
66+
return path_query or path_form
67+
68+
69+
def job_key_query_or_form(
70+
request: Request,
71+
job_key_query: Annotated[
72+
Optional[str],
73+
Query(
74+
alias="job_key",
75+
description=(
76+
"A key used to authenticate this request as acting on behalf or a job runner for the specified job."
77+
),
78+
),
79+
] = None,
80+
job_key_form: Annotated[
81+
Optional[str],
82+
Form(
83+
alias="job_key",
84+
description=(
85+
"A key used to authenticate this request as acting on behalf or a job runner for the specified job."
86+
),
87+
),
88+
] = None,
89+
):
90+
"""
91+
Accept `job_key` parameter both in query and form format.
92+
93+
This method does not force the client to provide the parameter, it could simply not submit the parameter in either
94+
format. To force the client to provide the parameter, coerce the output of the method to a string, i.e.
95+
`job_key: str = Depends(job_key_query_or_form)` so that FastAPI responds with status code 500 when the parameter is
96+
not provided.
97+
"""
98+
return job_key_query or job_key_form
99+
100+
51101
@router.cbv
52102
class FastAPIJobFiles:
53103
"""
@@ -139,15 +189,8 @@ def index(
139189
def create(
140190
self,
141191
job_id: Annotated[str, Path(description="Encoded id string of the job.")],
142-
path: Annotated[str, Form(description="Path to file to create.")],
143-
job_key: Annotated[
144-
str,
145-
Form(
146-
description=(
147-
"A key used to authenticate this request as acting on behalf or a job runner for the specified job."
148-
)
149-
),
150-
],
192+
path: Annotated[str, Depends(path_query_or_form)],
193+
job_key: Annotated[str, Depends(job_key_query_or_form)],
151194
file: UploadFile = File(None, description="Contents of the file to create."),
152195
session_id: str = Form(None),
153196
nginx_upload_module_file_path: str = Form(

0 commit comments

Comments
 (0)