Skip to content

Commit b732299

Browse files
rboni-dkclaude
andcommitted
refactor(api): apply TG-1107 review feedback
Degrade unmapped disposition values to no_decision instead of raising mid-serialization, matching result_status's tolerant mapping so one odd row never 500s the results page. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 3ce0373 commit b732299

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

testgen/api/runs.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ def get_test_run(job: JobExecution = resolve_job("view", JobExecution.job_key ==
7474
)
7575

7676

77+
def _disposition_from_db(value: str | None) -> Disposition:
78+
"""Map a stored ``disposition`` to the API enum, degrading unknown values to ``no_decision``.
79+
80+
A NULL or unmapped value resolves to ``no_decision`` rather than raising, so a single odd
81+
row never fails serialization of the whole results page.
82+
"""
83+
if not value:
84+
return Disposition.no_decision
85+
try:
86+
return DISPOSITION_FROM_DB[DbDisposition(value)]
87+
except (ValueError, KeyError):
88+
return Disposition.no_decision
89+
90+
7791
def _to_item(row: TestRunResultRow) -> TestResultItem:
7892
"""Map a DB-valued result row to the API item, normalizing enum casing."""
7993
return TestResultItem(
@@ -87,7 +101,7 @@ def _to_item(row: TestRunResultRow) -> TestResultItem:
87101
threshold_value=row.threshold_value,
88102
result_message=row.message,
89103
test_time=row.test_time,
90-
disposition=DISPOSITION_FROM_DB[DbDisposition(row.disposition)] if row.disposition else Disposition.no_decision,
104+
disposition=_disposition_from_db(row.disposition),
91105
)
92106

93107

tests/unit/api/test_runs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,11 @@ def test_list_results_status_render(mock_list, db_status, expected):
246246
"db_disposition,expected",
247247
[
248248
(None, Disposition.no_decision),
249+
("", Disposition.no_decision),
249250
("Confirmed", Disposition.confirmed),
250251
("Dismissed", Disposition.dismissed),
251252
("Inactive", Disposition.muted),
253+
("Bogus", Disposition.no_decision),
252254
],
253255
)
254256
@patch.object(TestResult, "list_for_run")

0 commit comments

Comments
 (0)