Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions aiohasupervisor/models/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class JobError(ResponseData):

type: str
message: str
stage: str | None


@dataclass(slots=True, frozen=True)
Expand Down
3 changes: 2 additions & 1 deletion tests/fixtures/jobs_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"errors": [
{
"type": "BackupInvalidError",
"message": "Invalid password for backup cfddca18"
"message": "Invalid password for backup cfddca18",
"stage": "restore_backup"
}
],
"created": "2025-01-30T20:55:15.000000+00:00",
Expand Down
24 changes: 24 additions & 0 deletions tests/fixtures/jobs_info_no_stage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"result": "ok",
"data": {
"ignore_conditions": ["free_space"],
"jobs": [
{
"name": "test_job_error_no_stage",
"reference": "test123",
"uuid": "3febe59311f94d6ba36f6f9f73357ca9",
"progress": 0,
"stage": null,
"done": true,
"errors": [
{
"type": "TestError",
"message": "Test error without stage field"
}
],
"created": "2025-01-30T20:55:12.859349+00:00",
"child_jobs": []
}
]
}
}
20 changes: 20 additions & 0 deletions tests/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
assert info.jobs[1].reference == "cfddca18"
assert info.jobs[1].errors[0].type == "BackupInvalidError"
assert info.jobs[1].errors[0].message == "Invalid password for backup cfddca18"
assert info.jobs[1].errors[0].stage == "restore_backup"


async def test_jobs_set_options(
Expand Down Expand Up @@ -112,3 +113,22 @@
assert responses.requests.keys() == {
("DELETE", URL(f"{SUPERVISOR_URL}/jobs/2febe59311f94d6ba36f6f9f73357ca8"))
}


async def test_jobs_info_backward_compatibility_no_stage(
responses: aioresponses, supervisor_client: SupervisorClient
) -> None:
"""Test jobs info API with error lacking stage field for backward compatibility."""
responses.get(
f"{SUPERVISOR_URL}/jobs/info",
status=200,
body=load_fixture("jobs_info_no_stage.json"),
)
info = await supervisor_client.jobs.info()

Check failure on line 127 in tests/test_jobs.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.12

test_jobs_info_backward_compatibility_no_stage mashumaro.exceptions.InvalidFieldValue: Field "jobs" of type list[Job] in JobsInfo has invalid value [{'name': 'test_job_error_no_stage', 'reference': 'test123', 'uuid': '3febe59311f94d6ba36f6f9f73357ca9', 'progress': 0, 'stage': None, 'done': True, 'errors': [{'type': 'TestError', 'message': 'Test error without stage field'}], 'created': '2025-01-30T20:55:12.859349+00:00', 'child_jobs': []}]

Check failure on line 127 in tests/test_jobs.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.13

test_jobs_info_backward_compatibility_no_stage mashumaro.exceptions.InvalidFieldValue: Field "jobs" of type list[Job] in JobsInfo has invalid value [{'name': 'test_job_error_no_stage', 'reference': 'test123', 'uuid': '3febe59311f94d6ba36f6f9f73357ca9', 'progress': 0, 'stage': None, 'done': True, 'errors': [{'type': 'TestError', 'message': 'Test error without stage field'}], 'created': '2025-01-30T20:55:12.859349+00:00', 'child_jobs': []}]
assert info.ignore_conditions == [JobCondition.FREE_SPACE]

assert info.jobs[0].name == "test_job_error_no_stage"
assert info.jobs[0].reference == "test123"
assert info.jobs[0].errors[0].type == "TestError"
assert info.jobs[0].errors[0].message == "Test error without stage field"
assert info.jobs[0].errors[0].stage is None
Loading