Summary
Several API endpoints in DataFileRoute.py (including /cleanUp, /resultsExists, /createCaseRun, /updateViews, and others) check conditions like:
if modelname != None or casename != None:
but fail to handle the case where the value is None.
When modelname or casename is None (for example, if the frontend sends a malformed request or the session is empty), the code skips the if block where the response variable is defined and drops directly into:
return jsonify(response), 200
Because response was never assigned a value, the server crashes with a fatal UnboundLocalError.
Expected behavior
If a required parameter like casename or modelname is None or omitted from the JSON payload, the API should handle it gracefully and return a structured error such as:
HTTP 400 Bad Request
{
"message": "Missing required parameter: modelname",
"status_code": "error"
}
This prevents a server crash and provides meaningful feedback to the client.
Reproduction steps
- Start the Flask application:
- Open a new PowerShell terminal and send a POST request with
null data:
Invoke-RestMethod `
-Uri "http://127.0.0.1:5002/cleanUp" `
-Method POST `
-Headers @{"Content-Type"="application/json"} `
-Body '{"modelname": null}'
- Observe the response:
HTTP 500 Internal Server Error
- Check the terminal where
python app.py is running.
You will see an unhandled traceback ending with:
UnboundLocalError: local variable 'response' referenced before assignment
(or on Python 3.11+)
UnboundLocalError: cannot access local variable 'response' where it is not associated with a value
Root Cause
The route logic only defines response inside a conditional block but still attempts to return it even when the condition fails.
Example pattern found in multiple endpoints:
if modelname != None:
response = {...}
return jsonify(response), 200
When modelname is None, response is never created.
Root Cause
The route logic only defines response inside a conditional block but still attempts to return it even when the condition fails.
Example pattern found in multiple endpoints:
if modelname != None:
response = {...}
return jsonify(response), 200
When modelname is None, response is never created.
Suggested Fix
Validate input parameters at the beginning of each endpoint and return a 400 Bad Request if they are missing or None.
Example:
modelname = request.json.get("modelname")
if modelname is None:
return jsonify({
"message": "Missing required parameter: modelname",
"status_code": "error"
}), 400
Alternatively, initialize response before conditional logic or restructure the control flow to ensure it is always defined.
Environment
Environment
| Field |
Value |
| OS |
Windows / Linux / macOS |
| Python |
Python 3.11+ |
| Branch |
main (latest commit) |
| Affected File |
API/Routes/DataFile/DataFileRoute.py |
Impact
- Causes 500 server crashes from malformed or incomplete client requests
- Affects multiple endpoints in
DataFileRoute.py
- Prevents proper API error handling and client-side debugging
Logs or screenshots

Summary
Several API endpoints in
DataFileRoute.py(including/cleanUp,/resultsExists,/createCaseRun,/updateViews, and others) check conditions like:but fail to handle the case where the value is
None.When
modelnameorcasenameisNone(for example, if the frontend sends a malformed request or the session is empty), the code skips theifblock where theresponsevariable is defined and drops directly into:Because
responsewas never assigned a value, the server crashes with a fatalUnboundLocalError.Expected behavior
If a required parameter like
casenameormodelnameisNoneor omitted from the JSON payload, the API should handle it gracefully and return a structured error such as:This prevents a server crash and provides meaningful feedback to the client.
Reproduction steps
nulldata:python app.pyis running.You will see an unhandled traceback ending with:
(or on Python 3.11+)
Root Cause
The route logic only defines
responseinside a conditional block but still attempts to return it even when the condition fails.Example pattern found in multiple endpoints:
When
modelnameisNone,responseis never created.Root Cause
The route logic only defines
responseinside a conditional block but still attempts to return it even when the condition fails.Example pattern found in multiple endpoints:
When
modelnameisNone,responseis never created.Suggested Fix
Validate input parameters at the beginning of each endpoint and return a
400 Bad Requestif they are missing orNone.Example:
Alternatively, initialize
responsebefore conditional logic or restructure the control flow to ensure it is always defined.Environment
Environment
main(latest commit)API/Routes/DataFile/DataFileRoute.pyImpact
DataFileRoute.pyLogs or screenshots