Skip to content

Fix 500 error on zero accuracy#81

Merged
pritamps merged 2 commits into
releasefrom
main
May 20, 2026
Merged

Fix 500 error on zero accuracy#81
pritamps merged 2 commits into
releasefrom
main

Conversation

@pritamps

Copy link
Copy Markdown
Contributor

No description provided.

pritamps and others added 2 commits May 20, 2026 18:06
The v2 report templates pipe `percentage` and `accuracy` through
`"%.Nf"|format(...)`, which raises TypeError on None and surfaces as a
Lambda 500. Upstream stores these as DynamoDB NULL when no questions
were attempted in a subject (e.g. a student skipped all 25 Maths
questions: 0 correct / 0 wrong is mathematically undefined, so the
producer wrote NULL rather than 0).

Two-layer fix:
- render_v2_report() now coerces None -> 0 for `percentage` and
  `accuracy` on both `overall_performance` and each entry in
  `subject_performance`, so any consumer of the v2 payload sees clean
  numerics.
- v2 and v2_print templates additionally guard each `%.Nf|format(...)`
  call with `or 0` as a defense-in-depth fallback.

Also imports `json` at the top of routers/student_quiz_reports.py —
it was used at line 656 (chapter_to_link_map = json.load(...)) but
never imported, a latent NameError on the v3 codepath that flake8
flagged when committing this change. One-line drive-by fix.

Follow-up worth filing separately: the v2 producer / ETL should emit
0.0 (or an explicit not-attempted flag) instead of NULL for these
fields, and any existing rows with NULL accuracy should be backfilled.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…-templates

Fix 500 on student_quiz_report_v2 when a subject is fully skipped
@pritamps pritamps merged commit 4ff1401 into release May 20, 2026
0 of 2 checks passed
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.

1 participant