Skip to content

Commit bf63fc2

Browse files
committed
fix(routers): status 500 when malformed jdls are given
1 parent 7f76615 commit bf63fc2

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

diracx-routers/src/diracx/routers/jobs/submission.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from http import HTTPStatus
66
from typing import Annotated
77

8-
from fastapi import Body, Depends, HTTPException
8+
from fastapi import Body, Depends, HTTPException, status
99
from pydantic import BaseModel
1010
from typing_extensions import TypedDict
1111

@@ -148,20 +148,26 @@ async def submit_bulk_jdl_jobs(
148148
initial_status = JobStatus.RECEIVED
149149
initial_minor_status = "Job accepted"
150150

151-
submitted_job_ids = await submit_jobs_jdl(
152-
[
153-
JobSubmissionSpec(
154-
jdl=jdl,
155-
owner=user_info.preferred_username,
156-
owner_group=user_info.dirac_group,
157-
initial_status=initial_status,
158-
initial_minor_status=initial_minor_status,
159-
vo=user_info.vo,
160-
)
161-
for jdl in job_desc_list
162-
],
163-
job_db=job_db,
164-
)
151+
try:
152+
submitted_job_ids = await submit_jobs_jdl(
153+
[
154+
JobSubmissionSpec(
155+
jdl=jdl,
156+
owner=user_info.preferred_username,
157+
owner_group=user_info.dirac_group,
158+
initial_status=initial_status,
159+
initial_minor_status=initial_minor_status,
160+
vo=user_info.vo,
161+
)
162+
for jdl in job_desc_list
163+
],
164+
job_db=job_db,
165+
)
166+
except ExceptionGroup as e:
167+
raise HTTPException(
168+
status_code=status.HTTP_400_BAD_REQUEST,
169+
detail="JDL syntax error",
170+
) from e
165171

166172
logging.debug(
167173
f'Jobs added to the JobDB", "{submitted_job_ids} for {user_info.preferred_username}/{user_info.dirac_group}'

diracx-routers/tests/test_job_manager.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@
7171
ParameterStart = 1;
7272
"""
7373

74+
TEST_MALFORMED_JDL = """
75+
[
76+
'Executable = "echo";'
77+
]
78+
"""
79+
7480
pytestmark = pytest.mark.enabled_dependencies(
7581
[
7682
"AuthSettings",
@@ -243,6 +249,12 @@ def test_insert_and_search(normal_user_client):
243249
assert r.json() == []
244250

245251

252+
def test_insert_malformed_jdl(normal_user_client):
253+
job_definitions = [TEST_MALFORMED_JDL]
254+
r = normal_user_client.post("/api/jobs/jdl", json=job_definitions)
255+
assert r.status_code == 400, r.json()
256+
257+
246258
def test_search_distinct(normal_user_client):
247259
"""Test that the distinct parameter works as expected."""
248260
job_definitions = [TEST_JDL, TEST_JDL, TEST_JDL]

0 commit comments

Comments
 (0)