Skip to content

Commit a28b55d

Browse files
Copilotagnersmdegat01
authored
Add stage field to JobError model (#167)
* Initial plan * Initial analysis of JobError stage field addition Co-authored-by: agners <[email protected]> * Add stage field to JobError model Co-authored-by: agners <[email protected]> * Apply suggestions from code review * Address prettier * Apply suggestions from code review Co-authored-by: Mike Degatano <[email protected]> * Apply suggestions from code review Co-authored-by: Mike Degatano <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: agners <[email protected]> Co-authored-by: Stefan Agner <[email protected]> Co-authored-by: Mike Degatano <[email protected]>
1 parent 11582e0 commit a28b55d

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

aiohasupervisor/models/jobs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class JobError(ResponseData):
4545

4646
type: str
4747
message: str
48+
stage: str | None
4849

4950

5051
@dataclass(slots=True, frozen=True)

tests/fixtures/jobs_info.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"errors": [
4949
{
5050
"type": "BackupInvalidError",
51-
"message": "Invalid password for backup cfddca18"
51+
"message": "Invalid password for backup cfddca18",
52+
"stage": "restore_backup"
5253
}
5354
],
5455
"created": "2025-01-30T20:55:15.000000+00:00",
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"result": "ok",
3+
"data": {
4+
"ignore_conditions": ["free_space"],
5+
"jobs": [
6+
{
7+
"name": "test_job_error_no_stage",
8+
"reference": "test123",
9+
"uuid": "3febe59311f94d6ba36f6f9f73357ca9",
10+
"progress": 0,
11+
"stage": null,
12+
"done": true,
13+
"errors": [
14+
{
15+
"type": "TestError",
16+
"message": "Test error without stage field",
17+
"stage": null
18+
}
19+
],
20+
"created": "2025-01-30T20:55:12.859349+00:00",
21+
"child_jobs": []
22+
}
23+
]
24+
}
25+
}

tests/test_jobs.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ async def test_jobs_info(
4242
assert info.jobs[1].reference == "cfddca18"
4343
assert info.jobs[1].errors[0].type == "BackupInvalidError"
4444
assert info.jobs[1].errors[0].message == "Invalid password for backup cfddca18"
45+
assert info.jobs[1].errors[0].stage == "restore_backup"
4546

4647

4748
async def test_jobs_set_options(
@@ -112,3 +113,22 @@ async def test_jobs_delete_job(
112113
assert responses.requests.keys() == {
113114
("DELETE", URL(f"{SUPERVISOR_URL}/jobs/2febe59311f94d6ba36f6f9f73357ca8"))
114115
}
116+
117+
118+
async def test_jobs_info_backward_compatibility_no_stage(
119+
responses: aioresponses, supervisor_client: SupervisorClient
120+
) -> None:
121+
"""Test jobs info API with error lacking stage field for backward compatibility."""
122+
responses.get(
123+
f"{SUPERVISOR_URL}/jobs/info",
124+
status=200,
125+
body=load_fixture("jobs_info_no_stage.json"),
126+
)
127+
info = await supervisor_client.jobs.info()
128+
assert info.ignore_conditions == [JobCondition.FREE_SPACE]
129+
130+
assert info.jobs[0].name == "test_job_error_no_stage"
131+
assert info.jobs[0].reference == "test123"
132+
assert info.jobs[0].errors[0].type == "TestError"
133+
assert info.jobs[0].errors[0].message == "Test error without stage field"
134+
assert info.jobs[0].errors[0].stage is None

0 commit comments

Comments
 (0)