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

feat: show rich error messages on past failed queries #15158

Merged
merged 2 commits into from
Jun 16, 2021

Conversation

betodealmeida
Copy link
Member

@betodealmeida betodealmeida commented Jun 15, 2021

SUMMARY

This PR makes SQL Lab show rich error messages when refreshing queries that failed.

The steps needed were:

  1. Modify superset/sql_lab.py so that the SIP-40 error payload gets saved with the query in the extra_json column under the errors key.
  2. Modify the south pane component to attach query.extra.errors to query.errors, so that errors are shown with the rich error component.
  3. [Optional: Add a custom column error to the SQLite engine spec in order to test.]

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before, when refreshing a failed query we'd see:

Screenshot 2021-06-14 at 17-57-06 Superset

After, when we refresh the page we see:

Screenshot 2021-06-14 at 17-55-58 Superset

TESTING INSTRUCTIONS

Tested manually with sync and async queries.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

Comment on lines -2430 to -2435
msg = data["error"]
query = _session.query(Query).filter_by(id=query_id).one()
database = query.database
db_engine_spec = database.db_engine_spec
errors = db_engine_spec.extract_errors(msg)
_session.close()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic was moved to superset/sql_lab.py

@betodealmeida betodealmeida changed the title Ch197b feat: show rich error messages on past failed queries Jun 15, 2021
@betodealmeida betodealmeida marked this pull request as ready for review June 15, 2021 00:58
Comment on lines +121 to +123
if (latestQuery?.extra?.errors) {
latestQuery.errors = latestQuery.extra.errors;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all that's needed to show the rich error messages in the FE.

from superset.utils import core as utils

if TYPE_CHECKING:
# prevent circular imports
from superset.models.core import Database


COLUMN_DOES_NOT_EXIST_REGEX = re.compile("no such column: (?P<column_name>.+)")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was testing with gsheets, so I decided to add this to have a custom error to test.

@codecov
Copy link

codecov bot commented Jun 15, 2021

Codecov Report

Merging #15158 (c8a4ede) into master (e2abf59) will increase coverage by 0.00%.
The diff coverage is 88.23%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #15158   +/-   ##
=======================================
  Coverage   77.41%   77.41%           
=======================================
  Files         969      969           
  Lines       49982    49988    +6     
  Branches     6422     6423    +1     
=======================================
+ Hits        38692    38697    +5     
- Misses      11087    11088    +1     
  Partials      203      203           
Flag Coverage Δ
hive 81.43% <93.33%> (+<0.01%) ⬆️
javascript 72.22% <50.00%> (-0.01%) ⬇️
mysql 81.71% <93.33%> (+<0.01%) ⬆️
postgres 81.72% <93.33%> (+<0.01%) ⬆️
python 82.10% <93.33%> (+<0.01%) ⬆️
sqlite 81.36% <93.33%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...tend/src/SqlLab/components/SouthPane/SouthPane.tsx 78.26% <50.00%> (-1.29%) ⬇️
superset/views/core.py 75.46% <75.00%> (-0.10%) ⬇️
superset/db_engine_specs/sqlite.py 97.29% <100.00%> (+0.42%) ⬆️
superset/sql_lab.py 82.22% <100.00%> (+0.32%) ⬆️

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 e2abf59...c8a4ede. Read the comment docs.

@@ -118,6 +118,9 @@ export default function SouthPane({
}
let results;
if (latestQuery) {
if (latestQuery?.extra?.errors) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
if (latestQuery?.extra?.errors) {
const { extra: { errors } } = latestQuery;
if (errors) {
latestQuery.errors = errors;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would fail if extra is not there, no?

>> const { extra: { errors } } = { foo: "bar" };
Uncaught TypeError: ({foo:"bar"}).extra is undefined

Though I just realized that I could've used if (latestQuery.extra?.errors) { instead, since we check if (latestQuery) already.

Copy link
Member

@hughhhh hughhhh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@betodealmeida betodealmeida merged commit d625f5f into apache:master Jun 16, 2021
cccs-RyanS pushed a commit to CybercentreCanada/superset that referenced this pull request Dec 17, 2021
* feat: store SIP-40 error payload with queries

* Set errors in query on load
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 29, 2021
* feat: store SIP-40 error payload with queries

* Set errors in query on load
cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
* feat: store SIP-40 error payload with queries

* Set errors in query on load
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.3.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 🚢 1.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants