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: Exception handling for SQL Lab views #30897

Merged
merged 2 commits into from
Nov 12, 2024

Conversation

michael-s-molina
Copy link
Member

SUMMARY

This PR adds the necessary rollback and responses for legacy SQL Lab views. The final solution should be moving these endpoints under the v1 namespace and use the command pattern for each operation with the @transaction annotation.

TESTING INSTRUCTIONS

CI should be sufficient.

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

@dosubot dosubot bot added the sqllab Namespace | Anything related to the SQL Lab label Nov 11, 2024
@@ -84,48 +85,56 @@ class TabStateView(BaseSupersetView):
@has_access_api
@expose("/", methods=("POST",))
def post(self) -> FlaskResponse:
query_editor = json.loads(request.form["queryEditor"])
Copy link
Member Author

Choose a reason for hiding this comment

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

The relevant change is the try/catch block.

Copy link

codecov bot commented Nov 11, 2024

Codecov Report

Attention: Patch coverage is 29.41176% with 60 lines in your changes missing coverage. Please review.

Project coverage is 83.88%. Comparing base (76d897e) to head (b4db6b0).
Report is 1134 commits behind head on master.

Files with missing lines Patch % Lines
superset/views/sql_lab/views.py 29.41% 60 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #30897       +/-   ##
===========================================
+ Coverage   60.48%   83.88%   +23.39%     
===========================================
  Files        1931      536     -1395     
  Lines       76236    38952    -37284     
  Branches     8568        0     -8568     
===========================================
- Hits        46114    32673    -13441     
+ Misses      28017     6279    -21738     
+ Partials     2105        0     -2105     
Flag Coverage Δ
hive 48.82% <9.41%> (-0.34%) ⬇️
javascript ?
mysql 76.71% <29.41%> (?)
postgres 76.83% <29.41%> (?)
presto 53.30% <9.41%> (-0.50%) ⬇️
python 83.88% <29.41%> (+20.39%) ⬆️
sqlite 76.29% <29.41%> (?)
unit 60.83% <1.17%> (+3.21%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines -173 to -176
if client_id := fields.get("latest_query_id"):
query = db.session.query(Query).filter_by(client_id=client_id).one_or_none()
if not query:
return self.json_response({"error": "Bad request"}, status=400)
Copy link
Member

Choose a reason for hiding this comment

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

I don't fully grasp why this was here in the first place (it would probably have been a good idea to add a comment here if this was in fact needed), but do you have any idea why

  • this was here?
  • it can be removed?

Copy link
Member Author

@michael-s-molina michael-s-molina Nov 12, 2024

Choose a reason for hiding this comment

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

This was an additional validation for when a client ID is no longer valid, which would generate a 500 response due to a foreign key error. Now the logic will return the same 400 error but without the extra expensive query.

@@ -1013,7 +1013,6 @@ def test_tabstate_update(self):
data = {"sql": json.dumps("select 1"), "latest_query_id": json.dumps(client_id)}
response = self.client.put(f"/tabstateview/{tab_state_id}", data=data)
assert response.status_code == 400
assert response.json["error"] == "Bad request"
Copy link
Member Author

@michael-s-molina michael-s-molina Nov 12, 2024

Choose a reason for hiding this comment

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

Validating the status_code here is sufficient as now the error will contain database specific and more rich exceptions.

Copy link
Member

Choose a reason for hiding this comment

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

Nice

Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -1013,7 +1013,6 @@ def test_tabstate_update(self):
data = {"sql": json.dumps("select 1"), "latest_query_id": json.dumps(client_id)}
response = self.client.put(f"/tabstateview/{tab_state_id}", data=data)
assert response.status_code == 400
assert response.json["error"] == "Bad request"
Copy link
Member

Choose a reason for hiding this comment

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

Nice

@michael-s-molina michael-s-molina merged commit c2885a1 into apache:master Nov 12, 2024
37 checks passed
michael-s-molina added a commit that referenced this pull request Nov 19, 2024
asher-lab added a commit to asher-lab/superset that referenced this pull request Nov 22, 2024
* fix: Exception handling for SQL Lab views (apache#30897)

* fix: don't show metadata for embedded dashboards (apache#30875)

* feat: add logging durations for screenshot async service (apache#30884)

* refactor(Avatar): Migrate Avatar to Ant Design 5 (apache#30740)

* refactor(input): Migrate Input component to Ant Design 5 (apache#30730)

* fix(empty dashboards): Allow downloading a screenshot of an empty dashboard (apache#30767)

Co-authored-by: Geido <60598000+geido@users.noreply.github.com>

* chore(ci): add tai and michael to helm owners (apache#30925)

* fix(helm): use submodule on helm release action (apache#30924)

* docs: add Free2Move to INTHEWILD.md (apache#30930)

* fix: blocks UI elements on right side (apache#30886)

Co-authored-by: Evan Rusackas <evan@preset.io>

* chore(deps): Migrate from `crate[sqlalchemy]` to `sqlalchemy-cratedb` (apache#29243)

* chore: update change log, UPDATING.md and bug-report.yml for 4.1 release (apache#30915)

* chore(docs): Update list of supported databases to include CrateDB (apache#30946)

* feat(trino,presto): add missing time grains (apache#30926)

* fix(Dashboard): Exclude edit param in async screenshot (apache#30962)

* fix(Card): Use correct class names for Ant Design 5 Card component (apache#30964)

* chore(Accessibility): Fix accessibility for 'Show x entries' dropdown in tables (apache#30818)

* build(deps): bump cross-spawn from 7.0.3 to 7.0.6 in /superset-frontend/cypress-base (apache#30969)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix(release validation): scripts now support RSA and EDDSA keys. (apache#30967)

* build(deps): bump cross-spawn from 7.0.3 to 7.0.6 in /docs (apache#30970)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore: add performance information to tooltip (apache#30948)

* fix(helm-chart): Fix broken PodDisruptionBudget due to introduction of extraLabels. (apache#30966)

* chore(helm): bumping app version to 4.1.1 in helm chart (apache#30918)

* chore: add unit tests for `is_mutating()` (apache#31021)

* chore(🦾): bump python numexpr 2.10.0 -> 2.10.1 (apache#31006)

Co-authored-by: GitHub Action <action@github.com>

* chore(🦾): bump python cffi 1.16.0 -> 1.17.1 (apache#31002)

Co-authored-by: GitHub Action <action@github.com>

* chore(🦾): bump python flask-babel subpackage(s) (apache#31000)

Co-authored-by: GitHub Action <action@github.com>

* fix(Dashboard): Retain colors when color scheme not set (apache#30646)

* fix(explore): verified props is not updated (apache#31008)

* chore: publish wheels (apache#30981)

* docs: Embedded sdk (apache#30972)

* fix(imports): import query_context for imports with charts (apache#30887)

* docs: Update doc about CSV upload (apache#30867)

Co-authored-by: Evan Rusackas <evan@preset.io>

* chore(🦾): bump python cattrs 23.2.3 -> 24.1.2 (apache#30998)

Co-authored-by: GitHub Action <action@github.com>

* fix(dataset): use sqlglot for DML check (apache#31024)

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
Co-authored-by: Joe Li <joe@preset.io>
Co-authored-by: Maxime Beauchemin <maximebeauchemin@gmail.com>
Co-authored-by: Mehmet Salih Yavuz <salih.yavuz@proton.me>
Co-authored-by: Geido <60598000+geido@users.noreply.github.com>
Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com>
Co-authored-by: Paolo Terzi <PaoloTerzi@users.noreply.github.com>
Co-authored-by: Sukuna <90980311+samarsrivastav@users.noreply.github.com>
Co-authored-by: Evan Rusackas <evan@preset.io>
Co-authored-by: Andreas Motl <andreas.motl@elmyra.de>
Co-authored-by: Andreas Motl <andreas.motl@crate.io>
Co-authored-by: Levis Mbote <111055098+LevisNgigi@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Elizabeth Thompson <eschutho@gmail.com>
Co-authored-by: Christoph Keller <github@christophkeller.cc>
Co-authored-by: lodu <48859312+lodu@users.noreply.github.com>
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: JUST.in DO IT <justin.park@airbnb.com>
Co-authored-by: David Hotham <david.hotham@microsoft.com>
Co-authored-by: Giampaolo Capelli <giampaolo.capelli@gmail.com>
Co-authored-by: Linden <zairrow@gmail.com>
Co-authored-by: Seiya <20365512+seiyab@users.noreply.github.com>
Co-authored-by: Asher Manangan <amanangan@powercosts.com>
sadpandajoe pushed a commit that referenced this pull request Dec 4, 2024
@sadpandajoe sadpandajoe added the v4.1 Label added by the release manager to track PRs to be included in the 4.1 branch label Dec 4, 2024
sadpandajoe pushed a commit that referenced this pull request Dec 4, 2024
sadpandajoe pushed a commit that referenced this pull request Dec 4, 2024
sadpandajoe pushed a commit that referenced this pull request Dec 4, 2024
sadpandajoe pushed a commit that referenced this pull request Dec 4, 2024
sadpandajoe pushed a commit that referenced this pull request Dec 5, 2024
nyohasstium pushed a commit to Webgains/superset that referenced this pull request Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/L sqllab Namespace | Anything related to the SQL Lab v4.1 Label added by the release manager to track PRs to be included in the 4.1 branch
Projects
Status: Cherried
Development

Successfully merging this pull request may close these issues.

3 participants