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

[dashboard] Refactor API using SIP-35 #9315

Merged
merged 11 commits into from
Mar 20, 2020

Conversation

dpgaspar
Copy link
Member

@dpgaspar dpgaspar commented Mar 16, 2020

CATEGORY

  • Bug Fix
  • Enhancement (new features, refinement)
  • Refactor
  • Add tests
  • Build / Development Environment
  • Documentation

SUMMARY

Refactor of the Dashboard API using SIP-35

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

REVIEWERS

@willbarrett, @craig-rueda, @villebro

@dpgaspar dpgaspar marked this pull request as ready for review March 17, 2020 17:01
from superset.extensions import db


def generic_create(model_cls: Model, properties: Dict, commit=True) -> Optional[Model]:
Copy link
Member

Choose a reason for hiding this comment

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

Don't pass in the class here. Instead, the caller will have created whatever instance he wants and then should pass it in. You can then combine your create / update into a single upsert method. Also, you can call this something like def upsert(model, commit=True)

Copy link
Member Author

Choose a reason for hiding this comment

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

We can do that and end up with less code. Yet I tend to think it's more readable this way (and easier to reason), DAO create methods call generic_create, update methods call generic_update, also Exceptions follow the same pattern.

Copy link
Member

Choose a reason for hiding this comment

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

I think we shouldn't combine create and update. If I'm trying to update a pre-existing record and someone deletes it in the interim from another process, I want that to error. Upsert would hide the race condition.

superset/dao/base.py Outdated Show resolved Hide resolved
superset/dao/base.py Outdated Show resolved Hide resolved
@codecov-io
Copy link

Codecov Report

Merging #9315 into master will not change coverage by %.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #9315   +/-   ##
=======================================
  Coverage   59.08%   59.08%           
=======================================
  Files         374      374           
  Lines       12205    12205           
  Branches     2989     2989           
=======================================
  Hits         7211     7211           
  Misses       4815     4815           
  Partials      179      179           
Impacted Files Coverage Δ
superset-frontend/src/explore/controls.jsx 40.14% <0.00%> (ø)

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 c36a7e3...3b69a1e. Read the comment docs.

Copy link
Member

@willbarrett willbarrett left a comment

Choose a reason for hiding this comment

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

Responding to an existing discussion and one suggestion for module location, but overall this looks good!

from superset.extensions import db


def generic_create(model_cls: Model, properties: Dict, commit=True) -> Optional[Model]:
Copy link
Member

Choose a reason for hiding this comment

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

I think we shouldn't combine create and update. If I'm trying to update a pre-existing record and someone deletes it in the interim from another process, I want that to error. Upsert would hide the race condition.

@@ -20,10 +20,11 @@
from typing import List, Optional
Copy link
Member

Choose a reason for hiding this comment

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

Would it be useful to move this file to tests/dashboards/api_tests.py? Following the implementation structure in the tests could help us find things in the future.

@dpgaspar dpgaspar merged commit c34df6b into apache:master Mar 20, 2020
@dpgaspar dpgaspar deleted the refactor/api-dashboard-sip-35 branch March 20, 2020 16:32
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.36.0 labels Feb 28, 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/XXL 🚢 0.36.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants