Copilot commented on code in PR #36105:
URL: https://github.com/apache/superset/pull/36105#discussion_r2535113018
##########
superset/sqllab/api.py:
##########
@@ -337,16 +337,32 @@ def get_results(self, **kwargs: Any) -> FlaskResponse:
params = kwargs["rison"]
key = params.get("key")
rows = params.get("rows")
- result = SqlExecutionResultsCommand(key=key, rows=rows).run()
+
+ try:
+ result = SqlExecutionResultsCommand(key=key, rows=rows).run()
+ except Exception as ex:
+ logger.exception("Error fetching query results for key=%s", key)
+ return self.response_500(message=str(ex))
# Using pessimistic json serialization since some database drivers can
return
# unserializeable types at times
- payload = json.dumps(
- result,
- default=json.pessimistic_json_iso_dttm_ser,
- ignore_nan=True,
- )
- return json_success(payload, 200)
+ try:
+ payload = json.dumps(
+ result,
+ default=json.pessimistic_json_iso_dttm_ser,
+ ignore_nan=True,
+ )
+ except Exception as ex:
+ logger.exception("Error serializing query results for key=%s", key)
+ return self.response_500(message="Unable to serialize query
results")
+
+ # Use json_success with explicit Content-Type to ensure Flask 2.3+
correctly
+ # handles the response and doesn't trigger HTTP 406 errors due to
content
+ # negotiation issues with Accept headers or proxy configurations
+ response = json_success(payload, 200)
+ # Explicitly set Content-Type as a safeguard against content
negotiation issues
Review Comment:
[nitpick] This comment is redundant with the comment on lines 359-361 which
already explains the purpose of setting the explicit Content-Type header.
Consider removing this duplicate comment or merging both comments into one
comprehensive explanation.
```suggestion
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]