Skip to content

fix: Use .get() with defaults in report_template.py to prevent KeyError crashes#39

Open
Devguru-codes wants to merge 1 commit intoOSIPI:mainfrom
Devguru-codes:Report_Template_Fix
Open

fix: Use .get() with defaults in report_template.py to prevent KeyError crashes#39
Devguru-codes wants to merge 1 commit intoOSIPI:mainfrom
Devguru-codes:Report_Template_Fix

Conversation

@Devguru-codes
Copy link

@Devguru-codes Devguru-codes commented Mar 2, 2026

render_report_html crashes with KeyError because it directly accesses keys that may not exist in the processor output. Three issues fixed:

Fix

-    params_html = "".join(f"<tr>..." for k, v in data["asl_parameters"])
-    missing_html = "".join(f"<li>..." for param in data["missing_parameters"])
+    asl_params = data.get("asl_parameters", [])
+    if isinstance(asl_params, dict):
+        asl_params = list(asl_params.items())
+    params_html = "".join(f"<tr>..." for k, v in asl_params)
+
+    missing = data.get("missing_parameters", data.get("missing_required_parameters", []))
+    if isinstance(missing, dict):
+        missing = list(missing.keys())
+    missing_html = "".join(f"<li>..." for param in missing)
+
+    basic_report = data.get("basic_report", "")
+    extended_report = data.get("extended_report", "")

File Changed

  • apps/backend/app/utils/report_template.py

API/Processor Responses Comparison

main branch (before fix)

ATTEMPTING render_report_html(processor_output):
CRASHED — KeyError: 'missing_parameters'
>> VERDICT: Bug is PRESENT.

Report_Template_Fix branch (after fix)

ATTEMPTING render_report_html(processor_output):
SUCCESS — HTML rendered
>> VERDICT: Bug is FIXED.

Python Test Suite Results

main branch (before fix)

# Test Status Detail
T1 Template renders with all keys present PASS
T2 Handles absent 'missing_parameters' FAIL KeyError
T3 Handles absent 'basic_report' FAIL KeyError
T4 Works with processor output format FAIL KeyError

Summary: PASSED=1 FAILED=3

Report_Template_Fix branch (after fix)

# Test Status Detail
T1 Template renders with all keys present PASS
T2 Handles absent 'missing_parameters' PASS
T3 Handles absent 'basic_report' PASS
T4 Works with processor output format PASS

Summary: PASSED=4 FAILED=0
Fixes #38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

render_report_html crashes with KeyError when processor output is missing expected keys

1 participant