Skip to content

fix: implement safe dictionary lookups in HTML template to prevent KeyError#54

Open
Aarshpatel12 wants to merge 1 commit intoOSIPI:mainfrom
Aarshpatel12:fix-issue-38
Open

fix: implement safe dictionary lookups in HTML template to prevent KeyError#54
Aarshpatel12 wants to merge 1 commit intoOSIPI:mainfrom
Aarshpatel12:fix-issue-38

Conversation

@Aarshpatel12
Copy link

Hi mentors! 👋

This PR addresses the PDF generation crash reported in Issue #38.

The Problem:

The render_report_html function was using strict dictionary lookups (e.g., data["basic_report"]). If the processor output omitted any of these keys, or changed the key names, it resulted in a fatal KeyError that crashed the endpoint.

The Solution:

  • Safe Lookups: Replaced strict lookups with .get() methods and provided sensible fallback strings (e.g., "No basic report available.") so the template always renders gracefully.
  • Format Flexibility: Added an isinstance check for asl_parameters so the template doesn't break whether it receives the data as a list of tuples (old format) or a dictionary (new format).
  • Key Fallbacks: Chained .get() lookups for missing parameters to safely check for both the new missing_required_parameters key and the old missing_parameters key.

(Note: I saw there was another PR open for this, but I wanted to submit this approach as it handles the asl_parameters type mismatch (dict vs list) mentioned in the issue description!)

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