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

feat: SavedQuery REST API for bulk delete and new API fields #10793

Merged
merged 7 commits into from
Sep 11, 2020

Conversation

dpgaspar
Copy link
Member

@dpgaspar dpgaspar commented Sep 4, 2020

SUMMARY

This PR introduces:

  • REST API to delete multiple saved queries in a bulk operation
  • Filter saved queries by created_by
  • Adds a post_update, post_add to add a user_id for fav and tags
  • Adds humanized changed on, and default sorts by it

Bulk delete swagger:
Screenshot 2020-09-04 at 13 47 31

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

@codecov-commenter
Copy link

codecov-commenter commented Sep 4, 2020

Codecov Report

Merging #10793 into master will increase coverage by 0.35%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10793      +/-   ##
==========================================
+ Coverage   61.22%   61.58%   +0.35%     
==========================================
  Files         802      429     -373     
  Lines       37814    13969   -23845     
  Branches     3555     3561       +6     
==========================================
- Hits        23153     8603   -14550     
+ Misses      14475     5180    -9295     
  Partials      186      186              
Flag Coverage Δ
#javascript 61.58% <ø> (-0.02%) ⬇️
#python ?

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

Impacted Files Coverage Δ
...et-frontend/src/components/RefreshChartOverlay.tsx 55.55% <0.00%> (-4.45%) ⬇️
...ontend/src/components/CertifiedIconWithTooltip.tsx 66.66% <0.00%> (-3.34%) ⬇️
...nd/src/views/CRUD/data/dataset/AddDatasetModal.tsx 57.57% <0.00%> (-2.43%) ⬇️
...rontend/src/components/ErrorMessage/ErrorAlert.tsx 20.83% <0.00%> (-1.62%) ⬇️
...erset-frontend/src/components/ListView/Filters.tsx 89.55% <0.00%> (-1.36%) ⬇️
...tend/src/views/CRUD/data/database/DatabaseList.tsx 86.95% <0.00%> (-1.18%) ⬇️
...end/src/views/CRUD/data/database/DatabaseModal.tsx 53.70% <0.00%> (-0.85%) ⬇️
...rontend/src/explore/components/PropertiesModal.tsx 59.70% <0.00%> (-0.60%) ⬇️
...frontend/src/views/CRUD/welcome/DashboardTable.tsx 78.37% <0.00%> (-0.57%) ⬇️
...perset-frontend/src/datasource/DatasourceModal.tsx 73.91% <0.00%> (-0.56%) ⬇️
... and 438 more

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 5199423...2871e26. Read the comment docs.

@dpgaspar dpgaspar changed the title feat: SavedQuery REST API for bulk delete feat: SavedQuery REST API for bulk delete and new API fields Sep 7, 2020
@@ -203,6 +203,10 @@ def sqlalchemy_uri(self) -> URL:
def url(self) -> str:
return "/superset/sqllab?savedQueryId={0}".format(self.id)

@property
def sql_tables(self) -> List[Table]:
return list(ParsedQuery(self.sql).tables)
Copy link
Member

Choose a reason for hiding this comment

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

It's too bad there isn't a great pattern to memoise this on the object that I'm aware of. Parsing queries gets expensive and I'd hate to see this called multiple times for the same object in a web request.

Copy link
Member

Choose a reason for hiding this comment

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

Seems premature, and unclear if calling a caching backend would perform better than doing the actual parsing...

Copy link
Member

@willbarrett willbarrett Sep 8, 2020

Choose a reason for hiding this comment

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

I was referring to the equivalent of Ruby's:

@parsed ||= ParsedQuery.new(self.sql)
return parsed.tables

which caches the result in-memory for the lifetime of the object :)

Copy link
Member

Choose a reason for hiding this comment

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

This isn't a blocker.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added an lru cache, not a big win since we will only cache the parsed query on an object instance itself. But will avoid possible repeated property get's during the instance lifetime.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually reverted this because of mypy
python/mypy#1362

Copy link
Member

Choose a reason for hiding this comment

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

That's fine, like I said it's not a blocker :)

item.user = g.user

def pre_update(self, item: SavedQuery) -> None:
self.pre_add(item)
Copy link
Member

Choose a reason for hiding this comment

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

This seems questionable - if an admin alters a saved query belonging to another user, should the ownership change?

Copy link
Member

Choose a reason for hiding this comment

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

+1, I wouldn't make the updater the owner, even though in the current model people should not see other's people saved queries, but this could change in the future.

Copy link
Member

Choose a reason for hiding this comment

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

+1 . Perhaps there should be an updated_by?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually there is a created_by and changed_by and I'm filtering the queries by created_by. This is here to maintain functionality for tags and fav, there is a SQLA listener that calls: https://github.com/apache/incubator-superset/blob/fd2d1c58c566d9312d6cfc5641a06ac2b03e753a/superset/models/tags.py#L225

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.

First pass comments

item.user = g.user

def pre_update(self, item: SavedQuery) -> None:
self.pre_add(item)
Copy link
Member

Choose a reason for hiding this comment

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

+1 . Perhaps there should be an updated_by?

superset/queries/saved_queries/dao.py Show resolved Hide resolved
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

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.

LGTM once CI passes

@dpgaspar dpgaspar merged commit 136f90f into apache:master Sep 11, 2020
@dpgaspar dpgaspar deleted the feat/savedqueries-bulk-del branch September 11, 2020 08:36
auxten pushed a commit to auxten/incubator-superset that referenced this pull request Nov 20, 2020
…10793)

* feat: SavedQuery REST API for bulk delete

* fix, singular msg and test

* remove 403 from OpenAPI spec

* filter by current user using created_by add sql_tables field

* fixes for new filter, add user field on pre_update, pre_add

* add lru cache to property

* Revert "add lru cache to property"

This reverts commit ad0d942
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.38.0 labels Mar 12, 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 🚢 0.38.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants