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

chore: migrate sqllab_viz endpoint to api v1 #23729

Merged
merged 14 commits into from
Apr 26, 2023
Merged

Conversation

hughhhh
Copy link
Member

@hughhhh hughhhh commented Apr 18, 2023

SUMMARY

Migrating legacy endpoint that creates datasets (superset/sqllab_viz) to api v1

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

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

@codecov
Copy link

codecov bot commented Apr 19, 2023

Codecov Report

Merging #23729 (a428ecc) into master (e8121b1) will decrease coverage by 0.01%.
The diff coverage is 75.00%.

❗ Current head a428ecc differs from pull request most recent head 7411635. Consider uploading reports for the commit 7411635 to get more accurate results

@@            Coverage Diff             @@
##           master   #23729      +/-   ##
==========================================
- Coverage   68.02%   68.02%   -0.01%     
==========================================
  Files        1936     1936              
  Lines       74929    74931       +2     
  Branches     8141     8141              
==========================================
+ Hits        50970    50971       +1     
- Misses      21871    21872       +1     
  Partials     2088     2088              
Flag Coverage Δ
hive 53.01% <100.00%> (+<0.01%) ⬆️
javascript 54.28% <71.42%> (-0.01%) ⬇️
mysql 78.80% <100.00%> (+<0.01%) ⬆️
postgres 78.87% <100.00%> (+<0.01%) ⬆️
presto 52.92% <100.00%> (+<0.01%) ⬆️
python 82.67% <100.00%> (+<0.01%) ⬆️
sqlite 77.39% <100.00%> (+<0.01%) ⬆️
unit 52.81% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
...d/src/SqlLab/components/SaveDatasetModal/index.tsx 50.00% <0.00%> (ø)
superset-frontend/src/SqlLab/actions/sqlLab.js 66.33% <50.00%> (-0.17%) ⬇️
...frontend/src/explore/actions/datasourcesActions.ts 100.00% <100.00%> (ø)
superset/views/core.py 75.33% <100.00%> (+0.01%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@@ -989,3 +1001,120 @@ def get_or_create_dataset(self) -> Response:
exc_info=True,
)
return self.response_422(message=ex.message)

@expose("/sqllab_viz/", methods=["POST"])
Copy link
Member

Choose a reason for hiding this comment

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

Instead of creating a new endpoint, could we instead re-use the POST /api/v1/dataset/ endpoint? It seems to serve the same purpose and has the validation being done in this endpoint automatically built-in

Copy link
Member

@jfrag1 jfrag1 left a comment

Choose a reason for hiding this comment

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

Nice, glad this approach works! There's still one place the endpoint needs to be updated, and some cleanup

schema: schema,
table_name: datasourceName,
sql: sql,
owners: [1],
Copy link
Member

Choose a reason for hiding this comment

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

the owners key can probably just be omitted from the payload here, then the backend should default to making the current user owner I believe

@@ -49,7 +49,7 @@ export function saveDataset({
const {
json: { data },
} = await SupersetClient.post({
endpoint: '/superset/sqllab_viz/',
endpoint: '/api/v1/dataset/sqllab_viz/',
Copy link
Member

Choose a reason for hiding this comment

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

This one will need be updated as well

Copy link
Member

Choose a reason for hiding this comment

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

Also since this is explore, the response payload from POST /api/v1/dataset/ maybe be missing keys that explore expects to be there in order to work properly. After this post we may need to make a request to GET /api/v1/dataset/{id}, which will return all needed keys. See here in a recent PR of mine where I had to do something similar: https://github.com/apache/superset/pull/23678/files#diff-ccfa293ffd1a07eab82f8646fcb2732ff5d001fec273656b18064db5115ac9fbR165

is_dttm = fields.Boolean(required=True, description="Name of table")


class SqllabVizSchema(Schema):
Copy link
Member

Choose a reason for hiding this comment

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

these can be removed

@@ -485,102 +485,6 @@ def test_pa_conversion_dict(self):
self.assertEqual(len(data), results.size)
self.assertEqual(len(cols), len(results.columns))

def test_sqllab_viz(self):
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think it's fine to leave in tests for deprecated endpoints, we can just delete them when they are eventually removed for good

@hughhhh hughhhh force-pushed the hxgh-apiv1-sqllab-viz branch 2 times, most recently from cd01015 to 0c8ae6a Compare April 21, 2023 18:46
Copy link
Member

@jfrag1 jfrag1 left a comment

Choose a reason for hiding this comment

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

LGTM, just one small thing

@@ -95,6 +95,7 @@ class DatasetRestApi(BaseSupersetModelRestApi):
"related_objects",
"duplicate",
"get_or_create_dataset",
"sqllab_viz",
Copy link
Member

Choose a reason for hiding this comment

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

this can be removed

Copy link
Member

@Antonio-RiveroMartnez Antonio-RiveroMartnez left a comment

Choose a reason for hiding this comment

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

LGTM! Concerns were addressed

Copy link
Member

@betodealmeida betodealmeida left a comment

Choose a reason for hiding this comment

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

Looks good, just a comment on the Length() validation that needs to be fixed.

superset/datasets/schemas.py Outdated Show resolved Hide resolved
superset/datasets/schemas.py Outdated Show resolved Hide resolved
@pull-request-size pull-request-size bot added size/M and removed size/L labels Apr 25, 2023
@hughhhh hughhhh merged commit fa8f984 into master Apr 26, 2023
54 checks passed
sebastianliebscher pushed a commit to sebastianliebscher/superset that referenced this pull request Apr 28, 2023
sadpandajoe added a commit to preset-io/superset that referenced this pull request Jun 1, 2023
sadpandajoe added a commit to preset-io/superset that referenced this pull request Jun 12, 2023
@villebro
Copy link
Member

@hughhhh @betodealmeida @jfrag1 @Antonio-RiveroMartnez this PR appears to have caused a nasty regression, namely it's now impossible to save a chart from a query that hasn't been saved as a dataset first: saving triggers an "Unknown field." error:

image

Interestingly the "Save as dataset" flow works:

image

This is happening, because in the main "Save" workflow we're sending a POST to /api/v1/dataset/ with the same type of payload that we were sending previously to /superset/sqllab_viz/:

image

As can be seen here, the schema doesn't support columns, nor template_params:

class DatasetPostSchema(Schema):
database = fields.Integer(required=True)
schema = fields.String(allow_none=True, validate=Length(0, 250))
table_name = fields.String(required=True, allow_none=False, validate=Length(1, 250))
sql = fields.String(allow_none=True)
owners = fields.List(fields.Integer())
is_managed_externally = fields.Boolean(allow_none=True, dump_default=False)
external_url = fields.String(allow_none=True)

I think we need to DRY up these flows, as it feels unnecessary to have a different code path for saving the dataset in "Save as dataset" vs the main "Save" button..

@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 3.0.0 labels Mar 13, 2024
@mistercrunch mistercrunch deleted the hxgh-apiv1-sqllab-viz branch March 26, 2024 17:56
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 🚢 3.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants