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(sql lab): Syntax errors should return with 422 status #20491

Conversation

diegomedina248
Copy link
Contributor

SUMMARY

A syntax error in SQL Lab, like the following:

select * from "FCC 2018 Survey" where par_region = 'US' land

returns a 500 error.

This PR changes the status to a 422, to reflect it as an user error instead.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

Execute a query with a syntax error in SQL Lab and observe the response status. Should be 422

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • 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

@diegomedina248 diegomedina248 force-pushed the fix/change-api-status-on-sql-lab-syntax-error branch from 32c7e7d to cf64245 Compare June 24, 2022 15:50
Copy link
Member

@eschutho eschutho left a comment

Choose a reason for hiding this comment

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

See comment.

except (SqlLabException, SupersetErrorsException) as ex:
except SupersetErrorsException as ex:
if all(ex.error_type == SupersetErrorType.SYNTAX_ERROR for ex in ex.errors):
ex.status = 422
Copy link
Member

Choose a reason for hiding this comment

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

This is great @diegomedina248. Thank you! Can we raise a new error instead of the original one? We may have to create a new syntax error class with a 422 status.

Copy link
Member

@AAfghahi AAfghahi left a comment

Choose a reason for hiding this comment

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

Love this, could you also include a test for this?

@pull-request-size pull-request-size bot added size/M and removed size/S labels Jun 27, 2022
@diegomedina248 diegomedina248 force-pushed the fix/change-api-status-on-sql-lab-syntax-error branch from 9ec5a09 to b2fe396 Compare June 27, 2022 12:46
@diegomedina248 diegomedina248 force-pushed the fix/change-api-status-on-sql-lab-syntax-error branch from b2fe396 to 9fb87b1 Compare June 27, 2022 12:59
@diegomedina248
Copy link
Contributor Author

Love this, could you also include a test for this?

The overall flow is covered by integration tests, but there's no command test setup for sqllab, and that setup could take a while. Will follow up with another pr for that one

if all(ex.error_type == SupersetErrorType.SYNTAX_ERROR for ex in ex.errors):
raise SupersetSyntaxErrorException(ex.errors) from ex
raise ex
except SupersetException as ex:
Copy link
Member

Choose a reason for hiding this comment

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

I noticed that we were catching SqlLabException before. This one is a parent class, correct, so it should still work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, correct, and most likely that exception will be thrown as is, unless it matches the criteria

Copy link
Member

@eschutho eschutho left a comment

Choose a reason for hiding this comment

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

Thanks @diegomedina248!

@rusackas rusackas merged commit 383313b into apache:master Jul 27, 2022
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.1.0 and removed 🚢 2.1.3 labels Mar 13, 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 Preset-Patch size/M 🚢 2.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants