Skip to content

fix: guard remaining DataFileRoute endpoints against null #439

Open
parthdagia05 wants to merge 1 commit intoEAPD-DRB:mainfrom
parthdagia05:fix/unbound-local-datafile-routes
Open

fix: guard remaining DataFileRoute endpoints against null #439
parthdagia05 wants to merge 1 commit intoEAPD-DRB:mainfrom
parthdagia05:fix/unbound-local-datafile-routes

Conversation

@parthdagia05
Copy link
Copy Markdown

Linked issue

Existing related work reviewed

Overlap assessment

Why this PR should proceed

Summary

  • What changed: Added early return 400 guards to 8 DataFileRoute endpoints (generateDataFile, createCaseRun, updateCaseRun, deleteScenarioCaseRuns, saveView, updateViews, batchRun, cleanUp).
  • Why: These routes crash with UnboundLocalError when casename/modelname is null, producing a raw 500 with a full stack trace instead of a clean 400 JSON response.

Validation

  • Tests added/updated (or not applicable) - N/A: guard pattern is identical to existing deleteCaseRun guard. Existing smoke tests cannot run without Python 3.10-3.12.
  • Validation steps documented
  • Evidence attached

python -m py_compile API/Routes/DataFile/DataFileRoute.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/unbound-local-datafile-routes)
  • Change is deliverable without upstream OSeMOSYS/MUIO dependency
  • Base repo/branch is EAPD-DRB/MUIOGO:main

Exception rationale

N/A

…delname

Eight endpoints in DataFileRoute.py crash with UnboundLocalError when
the request body contains a null casename or modelname. The if-None
conditional skips the body, response is never assigned, and
return jsonify(response) raises UnboundLocalError - producing a raw
500 Internal Server Error with a full stack trace.

Affected routes: generateDataFile, createCaseRun, updateCaseRun,
deleteScenarioCaseRuns, saveView, updateViews, batchRun, cleanUp.

Fix: add an early return with 400 Bad Request before each conditional,
using the same guard pattern already present in deleteCaseRun (line 77).

This is a follow-up to PR EAPD-DRB#253 which fixed the same bug class in
readDataFile and validateInputs but left the other eight routes
unguarded. Also a sibling of issue EAPD-DRB#288 (batchRun crash).
@parthdagia05
Copy link
Copy Markdown
Author

@SeaCelo follow-up to #253 which fixed this crash in readDataFile/validateInputs. Same guard pattern you used in deleteCaseRun, applied to the 8 remaining unguarded routes.

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] UnboundLocalError on 8 DataFileRoute endpoints when casename/modelname is null

1 participant