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(api v1): Deprecate datasource/save and datasource/get endpoints #23678

Merged
merged 21 commits into from
Apr 19, 2023

Conversation

jfrag1
Copy link
Member

@jfrag1 jfrag1 commented Apr 13, 2023

SUMMARY

Deprecates the datasource/save and datasource/get endpoints. They can be replaced with the existing PUT /api/v1/dataset/{pk} and GET /api/v1/dataset/{pk} endpoints.

Several fields that the frontend expects needed to be added to the payload on the GET endpoint so that explore doesn't break after swapping datasets

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 13, 2023

Codecov Report

Merging #23678 (d5c2955) into master (0974fa1) will increase coverage by 0.02%.
The diff coverage is 83.07%.

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

@@            Coverage Diff             @@
##           master   #23678      +/-   ##
==========================================
+ Coverage   68.08%   68.11%   +0.02%     
==========================================
  Files        1920     1922       +2     
  Lines       73991    74068      +77     
  Branches     8092     8101       +9     
==========================================
+ Hits        50374    50448      +74     
  Misses      21548    21548              
- Partials     2069     2072       +3     
Flag Coverage Δ
hive 53.19% <86.84%> (+0.01%) ⬆️
javascript 54.14% <76.08%> (+0.05%) ⬆️
mysql 79.22% <100.00%> (+0.01%) ⬆️
postgres 79.30% <100.00%> (+0.01%) ⬆️
presto 53.11% <86.84%> (+0.01%) ⬆️
python 83.15% <100.00%> (+0.01%) ⬆️
sqlite 77.79% <89.47%> (+<0.01%) ⬆️
unit 53.04% <78.94%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
...ackages/superset-ui-chart-controls/src/fixtures.ts 100.00% <ø> (ø)
...d/packages/superset-ui-chart-controls/src/types.ts 100.00% <ø> (ø)
...ackages/superset-ui-core/src/utils/featureFlags.ts 100.00% <ø> (ø)
...onents/Chart/ChartContextMenu/ChartContextMenu.tsx 76.19% <ø> (ø)
...end/src/dashboard/components/SliceHeader/index.tsx 90.56% <ø> (ø)
...onfigModal/FiltersConfigForm/FiltersConfigForm.tsx 55.17% <0.00%> (ø)
superset-frontend/src/dashboard/constants.ts 100.00% <ø> (ø)
...ontrols/DndColumnSelectControl/DndFilterSelect.tsx 42.27% <0.00%> (ø)
...ontrols/DndColumnSelectControl/DndMetricSelect.tsx 47.86% <0.00%> (+0.40%) ⬆️
superset-frontend/src/explore/fixtures.tsx 75.00% <ø> (ø)
... and 16 more

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

and not is_safe_url(default_endpoint)
and current_app.config["PREVENT_UNSAFE_DEFAULT_URLS_ON_DATASET"]
):
exceptions.append(DatasetEndpointUnsafeValidationError())
Copy link
Member Author

Choose a reason for hiding this comment

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

Porting this check over from the datasource/save endpoint

@@ -67,7 +67,7 @@ export interface Dataset {
type: DatasourceType;
columns: ColumnMeta[];
metrics: Metric[];
column_format: Record<string, string>;
column_formats: Record<string, string>;
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 believe this was a typo, the backend returns column_formats

@jfrag1 jfrag1 closed this Apr 13, 2023
@jfrag1 jfrag1 reopened this Apr 13, 2023
@jfrag1 jfrag1 closed this Apr 13, 2023
@jfrag1 jfrag1 reopened this Apr 13, 2023
SupersetClient.put({
endpoint: `/api/v1/dataset/${currentDatasource.id}`,
jsonPayload: {
table_name: currentDatasource.table_name,

Choose a reason for hiding this comment

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

Why are we not spreading as we were before? same with metric and column below.

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 old endpoint didn't have a rigid structure it accepted as a payload; it would just take a JSON string, parse it, and then set all keys that it was able to set on the target dataset, ignoring irrelevant keys.

The new endpoint is different; it accepts the payload defined by the DatasetPutSchema, which only includes the relevant keys that can be updated. If the payload contains any other keys, the endpoint 400's. The datasource object here contains several of these other irrelevant keys, so now we have to extract only the ones that are needed.

metrics: currentDatasource?.metrics?.map(
(metric: Record<string, unknown>) => ({
...metric,
SupersetClient.put({
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to save a new dataset in this modal or only update?

Copy link
Member Author

Choose a reason for hiding this comment

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

only update, the datasource/save endpoint only supported updating an existing dataset, not creating a new one

Copy link
Member

Choose a reason for hiding this comment

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

Ok, perfect.

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.

Awesome work!

@eschutho eschutho merged commit 44557f5 into apache:master Apr 19, 2023
@eschutho eschutho deleted the jack/migrate-datasource-apis-to-v1 branch April 19, 2023 00:51
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 May 5, 2023
sadpandajoe added a commit to preset-io/superset that referenced this pull request May 12, 2023
@jfrag1 jfrag1 mentioned this pull request May 18, 2023
9 tasks
@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
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/L 🚢 3.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants