fix: add input validation to critical API routes to prevent 500 on mi…#79
fix: add input validation to critical API routes to prevent 500 on mi…#79pigeio wants to merge 2 commits intoEAPD-DRB:mainfrom
Conversation
|
@pigeio Great catch on fixing these 500 errors! UX-wise, this is a much-needed improvement. Reviewing the diff, I noticed As a longer-term architectural note: for the Track 1 OG-CLEWS integration (PR #24), we are using Pydantic ( For this PR, extracting to |
ade6430 to
3e15bbf
Compare
|
@NamanmeetSingh Good point — extracted to a shared |
…ssing fields
Summary
What changed: Added a [validate_json_fields()] helper to [CaseRoute.py] and [DataFileRoute.py]. Applied it to the 10 most critical POST routes (
/deleteCase,/copyCase,/saveCase,/saveParamFile,/saveScOrder,/run,/batchRun,/deleteCaseRun,/createCaseRun,/updateCaseRun). Missing or malformed JSON now returns 400 Bad Request with a descriptive error instead of crashing with an unhandled 500 KeyError.Why: All POST routes accessed
request.json['key']directly. If any field was missing, the server crashed withKeyError— theexceptblocks only caughtIOError/OSError, neverKeyError.Related issues
Validation
Both files pass
py_compilesyntax check. 13/13 unit tests passed covering:Documentation
Scope check
OSeMOSYS/MUIOdependencyEAPD-DRB/MUIOGO:main(not upstream)EAPD-DRB/MUIOGO:mac-port