Skip to content

fix: add missing request field validation to all ViewDataRoute endpoints#448

Open
parthdagia05 wants to merge 1 commit intoEAPD-DRB:mainfrom
parthdagia05:fix/viewdataroute-missing-input-validation
Open

fix: add missing request field validation to all ViewDataRoute endpoints#448
parthdagia05 wants to merge 1 commit intoEAPD-DRB:mainfrom
parthdagia05:fix/viewdataroute-missing-input-validation

Conversation

@parthdagia05
Copy link
Copy Markdown

Linked issue

Existing related work reviewed

Overlap assessment

Why this PR should proceed

  • Completes acknowledged-but-incomplete validation coverage. Uses the existing validate_json_fields utility identically to every other route file. 1 file, 13 lines added, zero behavior change for valid requests. updateViewData and updateTEViewData are core data editing routes every cell edit in the parameter grid hits them.

Summary

  • What changed: Added validate_json_fields() calls to all 4 ViewDataRoute.py endpoints (viewData, viewTEData, updateViewData, updateTEViewData).
  • Why: Missing field in any request body crashes with KeyError → raw 500 stack trace. Every other route file already validates; ViewDataRoute was skipped.

Validation

  • Tests added/updated (or not applicable) - N/A: uses existing validate_json_fields utility which is already tested.
  • Validation steps documented
  • Evidence attached

python -m py_compile API/Routes/Case/ViewDataRoute.py passes. git diff --check clean. Branched off latest upstream/main (5f8f89a).

Documentation

  • Docs updated in this PR (or not applicable) - N/A
  • Any setup/workflow changes reflected in repo docs - N/A

Scope check

  • No unrelated refactors
  • Implemented from a feature branch (fix/viewdataroute-missing-input-validation)
  • Change is deliverable without upstream OSeMOSYS/MUIO dependency
  • Base repo/branch is EAPD-DRB/MUIOGO:main

Exception rationale

N/A

All four ViewDataRoute.py endpoints access request.json fields
directly without validate_json_fields, unlike every other route
file in the API. A request with any missing field crashes with
KeyError and returns a raw 500 stack trace to the client.

This was the same bug class fixed by PR EAPD-DRB#79 across 10 other routes
and tracked in issues EAPD-DRB#77 and EAPD-DRB#185, but ViewDataRoute was missed
when those fixes landed.

Adds validate_json_fields calls to:
- viewData (1 field: casename)
- viewTEData (1 field: casename)
- updateViewData (10 fields: casename, year, ScId, groupId,
  paramId, TechId, CommId, EmisId, Timeslice, value)
- updateTEViewData (7 fields: casename, scId, groupId, paramId,
  techId, emisId, value)
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.

[Bug] ViewDataRoute endpoints crash with KeyError 500 due to missing request field validation

1 participant