-
-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Description
Detail Bug Report
Summary
- Context: The
monitoring_queryfunction handles GET requests to/monitoring/queries/{sfqid}endpoint, which is used by the Snowflake Python connector to check query status for async queries. - Bug: The
monitoring_queryfunction does not handleServerErrorexceptions that can be raised byto_token()andto_conn(). - Actual vs. expected: When authentication fails (missing or invalid token), the function returns a 500 Internal Server Error instead of a 401 Unauthorized error with proper JSON error response.
- Impact: Clients receive generic 500 errors instead of proper 401 authentication errors, making it difficult to diagnose authentication issues and potentially causing the Snowflake connector's error handling to fail unexpectedly.
Code with bug
def monitoring_query(request: Request) -> JSONResponse:
token = to_token(request) # <-- BUG π΄ Can raise ServerError, but not caught
conn = to_conn(token)
sfqid = request.path_params["sfqid"]
if not conn.results_cache.get(sfqid):
return JSONResponse({"data": {"queries": []}, "success": True})
return JSONResponse({"data": {"queries": [{"status": "SUCCESS"}]}, "success": True})Example
- Without Authorization header:
to_token(request)raisesServerError(status_code=401, code="390101", message="Authorization header not found in the request data.").- Unhandled in
monitoring_query, Starlette returns 500 Internal Server Error to the client.
- With invalid token:
to_conn(token)raisesServerError(status_code=401, code="390104", message="User must login again to access the service.").- Unhandled in
monitoring_query, resulting in 500 Internal Server Error.
Recommended fix
Wrap the calls in a try-except and return a JSON error response consistent with other endpoints:
def monitoring_query(request: Request) -> JSONResponse:
try: # <-- FIX π’
token = to_token(request)
conn = to_conn(token)
sfqid = request.path_params["sfqid"]
if not conn.results_cache.get(sfqid):
return JSONResponse({"data": {"queries": []}, "success": True})
return JSONResponse({"data": {"queries": [{"status": "SUCCESS"}]}, "success": True})
except ServerError as e: # <-- FIX π’
return JSONResponse(
{"data": None, "code": e.code, "message": e.message, "success": False, "headers": None},
status_code=e.status_code,
)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels