New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(chart-data-api): improve chart data endpoint errors #10300
fix(chart-data-api): improve chart data endpoint errors #10300
Conversation
Codecov Report
@@ Coverage Diff @@
## master #10300 +/- ##
==========================================
- Coverage 70.58% 65.60% -4.99%
==========================================
Files 600 600
Lines 32103 32107 +4
Branches 3244 3245 +1
==========================================
- Hits 22661 21063 -1598
- Misses 9339 10863 +1524
- Partials 103 181 +78
Continue to review full report at Codecov.
|
f7f4c1b
to
a2846a8
Compare
) | ||
try: | ||
query_context.raise_for_access() | ||
except SupersetSecurityException: | ||
return self.response_401() | ||
payload = query_context.get_payload() | ||
for query in payload: | ||
if query["error"]: | ||
return self.response_400(message=f"Error: {query['error']}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be great if query_context.get_payload()
would raise custom superset exceptions instead of checking for errors on the payload. But we can address that later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great idea 👍 To unblock 0.37
I'll merge this as-is, but will improve exception handling after we ship the release.
* fix: improve chart data error response * Populate error_message in QueryResult * add tests * Lint + fix incorrect raise * add more tests
* fix: improve chart data error response * Populate error_message in QueryResult * add tests * Lint + fix incorrect raise * add more tests
* fix: improve chart data error response * Populate error_message in QueryResult * add tests * Lint + fix incorrect raise * add more tests
SUMMARY
TL;DR: this makes viz plugins behave in the same way as legacy viz plugins when the request fails or returns no data.
This fixes the following problems in the chart data endpoint:
QueryContext
was updated to return a non-error response with an empty data field for empty result sets.error_message
property ofQueryResult
was not being populated for failed requests in SQLA model, leading to theerror
field onQueryObject
always beingNone
.QueryObject
s when calling the chart data endpoint. This meant that erroneous requests were returned as 200s with an error-field that was not handled in any way, causing the chart to render in unexpected ways. Now theerror
field is is checked for each response dataset; if a single one is defined, a 400 is returned (these are mostly expected to be incorrect SQL).BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
AFTER
When no data is returned, the chart data endpoint returns a response that the
Chart
component can properly identify as an empty response. Previously this left the previous rendered state visible.When an incorrect request is performed, the error message is displayed, making debugging easier. Previously only "An error occurred." was displayed (please note that the error in this screenshot has been fixed by #10299).
When an a query is incorrect, the error is displayed in the warning (previously this would print "An error occurred while rendering the visualization: TypeError: Cannot read property 'map' of undefined")
TEST PLAN
Local testing.
ADDITIONAL INFORMATION