Skip to content

Commit 4b0fa1f

Browse files
github-actions[bot]matheushent
andauthoredMar 7, 2025··
fix(agent): update the validate_job_state validator to support data_parser 0.0.40 (#739) (#742)
This commit modifies the validator function `validate_job_state` from the `SlurmJobData` model in order to support the data_parser 0.0.40. Essentialy, in Slurm 24.11, the `--json` flag from the `scontrol show job` command uses the data_parser 0.0.40. According to the official [documentation](https://slurm.schedmd.com/job_state_codes.html#overview), the job flags can be returned alongside the job state, which can make the `job_state` key to have multiple keys. (cherry picked from commit 1d97b8c) Co-authored-by: Matheus Tosta <[email protected]>
1 parent ee6277a commit 4b0fa1f

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed
 

‎changes/agent/739.fixed.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Updated the `validate_job_state` validator to support data_parser 0.0.40.
2+
3+
In Slurm 24.11, the `--json` flag from the `scontrol show job` command uses the
4+
data_parser 0.0.40. According to the official [documentation](https://slurm.schedmd.com/job_state_codes.html#overview),
5+
the job flags can be returned alongside the job state, which can make the `job_state` key to have multiple keys. This
6+
change prevents any validation error when fetching job's data by returning the first available state.

‎jobbergate-agent/jobbergate_agent/jobbergate/schemas.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ def validate_job_state(cls, value: str | list[str] | None) -> str | None:
8989
return None
9090

9191
if isinstance(value, list):
92-
if len(value) != 1:
93-
raise ValueError("job_state does not have exactly one value.")
92+
if len(value) == 0:
93+
raise ValueError("job_state does not have at least one value.")
94+
# from data_parser 0.0.40, the Slurm API can return multiple states
95+
# [Reference](https://slurm.schedmd.com/job_state_codes.html#overview)
9496
return value[0]
9597
return value
9698

‎jobbergate-agent/tests/jobbergate/test_update.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ async def test_fetch_job_data__handles_list_in_job_state():
119119
async def test_fetch_job_data__raises_error_if_job_state_is_invalid_list():
120120
"""
121121
Test that the ``fetch_job_data()`` function raises an exception
122-
if the list slurm_job_state does not have exactly one value.
122+
if the list slurm_job_state does not have at least one value.
123123
"""
124124
mocked_sbatch = mock.MagicMock()
125125
mocked_sbatch.get_job_info.return_value = dict(
@@ -129,7 +129,7 @@ async def test_fetch_job_data__raises_error_if_job_state_is_invalid_list():
129129
foo="bar",
130130
)
131131

132-
with pytest.raises(SbatchError, match="does not have exactly one value"):
132+
with pytest.raises(SbatchError, match="does not have at least one value"):
133133
await fetch_job_data(123, mocked_sbatch)
134134

135135

0 commit comments

Comments
 (0)
Please sign in to comment.