Skip to content
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

Merged
merged 5 commits into from Jul 14, 2020

Conversation

villebro
Copy link
Member

@villebro villebro commented Jul 13, 2020

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:

  • if no data was returned, the chart would not render, leaving the old chart on screen, potentially even an incorrect chart type. This was due to the legacy endpoint returning a 200 with empty data, as opposed to the new endpoint returning a 200 response with an error field but without a data field. To harmonize behavior, QueryContext was updated to return a non-error response with an empty data field for empty result sets.
  • The error_message property of QueryResult was not being populated for failed requests in SQLA model, leading to the error field on QueryObject always being None.
  • Errors were not picked up from QueryObjects 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 the error 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).
  • The error message from erroneous requests (=incorrect request schema) were not displayed, making it difficult to see in the frontend what the problem was.

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.
image

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).
image

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")
image

TEST PLAN

Local testing.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

@villebro villebro changed the title fix: improve chart data endpoint errors fix(chart-data-api): improve chart data endpoint errors Jul 13, 2020
@codecov-commenter
Copy link

codecov-commenter commented Jul 13, 2020

Codecov Report

Merging #10300 into master will decrease coverage by 4.98%.
The diff coverage is 80.00%.

Impacted file tree graph

@@            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     
Flag Coverage Δ
#cypress ?
#javascript 59.56% <0.00%> (-0.01%) ⬇️
#python 69.81% <88.88%> (+0.04%) ⬆️
Impacted Files Coverage Δ
superset-frontend/src/chart/Chart.jsx 10.20% <0.00%> (-56.47%) ⬇️
superset/charts/api.py 73.61% <80.00%> (+0.34%) ⬆️
superset/common/query_context.py 80.12% <100.00%> (+0.38%) ⬆️
superset/connectors/sqla/models.py 89.88% <100.00%> (+0.92%) ⬆️
superset-frontend/src/SqlLab/App.jsx 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/explore/App.jsx 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/SqlLab/index.jsx 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/dashboard/App.jsx 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/explore/index.jsx 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/dashboard/index.jsx 0.00% <0.00%> (-100.00%) ⬇️
... and 150 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 96e0da9...960c7b7. Read the comment docs.

@villebro villebro changed the title fix(chart-data-api): improve chart data endpoint errors [WIP] fix(chart-data-api): improve chart data endpoint errors Jul 14, 2020
@villebro villebro added the v0.37 label Jul 14, 2020
@villebro villebro force-pushed the villebro/chart-data-error-msg branch from f7f4c1b to a2846a8 Compare July 14, 2020 07:52
@pull-request-size pull-request-size bot added size/M and removed size/S labels Jul 14, 2020
@villebro villebro changed the title [WIP] fix(chart-data-api): improve chart data endpoint errors fix(chart-data-api): improve chart data endpoint errors Jul 14, 2020
)
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']}")
Copy link
Member

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

Copy link
Member Author

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.

@villebro villebro merged commit c44ee06 into apache:master Jul 14, 2020
@villebro villebro deleted the villebro/chart-data-error-msg branch July 14, 2020 09:41
villebro added a commit that referenced this pull request Jul 14, 2020
* fix: improve chart data error response

* Populate error_message in QueryResult

* add tests

* Lint + fix incorrect raise

* add more tests
auxten pushed a commit to auxten/incubator-superset that referenced this pull request Nov 20, 2020
* fix: improve chart data error response

* Populate error_message in QueryResult

* add tests

* Lint + fix incorrect raise

* add more tests
cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
* fix: improve chart data error response

* Populate error_message in QueryResult

* add tests

* Lint + fix incorrect raise

* add more tests
@mistercrunch mistercrunch added 🍒 0.37.0 🍒 0.37.1 🍒 0.37.2 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.38.0 labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/M v0.37 🍒 0.37.0 🍒 0.37.1 🍒 0.37.2 🚢 0.38.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants