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(api): unable to delete virtual dataset, wrong permission name #11019

Merged
merged 9 commits into from
Sep 29, 2020

Conversation

dpgaspar
Copy link
Member

@dpgaspar dpgaspar commented Sep 23, 2020

SUMMARY

When creating a virtual dataset using SQLLab -> Explorer the call to superset/sqllab_viz creates a new SqlaTable with database_id set, not database. This causes a problem on the SQLAlchemy listener that creates/updates permissions on insert/update. Because the database relation is not set yet at this time the get_perm() method on the SqlaTable return a permission with [None].[<VIRTUAL DS NAME>](id:22) instead of [examples].[<VIRTUAL_DS_NAME>](id:22)

When deleting the new dataset delete command will check if the permission for the dataset exists (to delete it also) and this sanity check failed, refusing to delete the dataset. We will delete the dataset and just log an error on this PR.

Also added a migration revision that does its best on fixing any existing faulty data access permissions.

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

@dpgaspar dpgaspar changed the title fix(api): unable to delete virtual dataset because of wrong permissio… fix(api): unable to delete virtual dataset, wrong permission name Sep 23, 2020
@pull-request-size pull-request-size bot added size/M and removed size/S labels Sep 24, 2020
@pull-request-size pull-request-size bot added size/L and removed size/M labels Sep 24, 2020
if not view_menu:
logger.error(
"Could not find the data access permission for the dataset"
)
Copy link
Member Author

@dpgaspar dpgaspar Sep 24, 2020

Choose a reason for hiding this comment

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

If a dataset permission does not exist, log the error and delete anyway

@dpgaspar dpgaspar marked this pull request as ready for review September 24, 2020 11:46
@dpgaspar dpgaspar changed the title fix(api): unable to delete virtual dataset, wrong permission name [WiP] fix(api): unable to delete virtual dataset, wrong permission name Sep 24, 2020
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

@dpgaspar dpgaspar changed the title [WiP] fix(api): unable to delete virtual dataset, wrong permission name fix(api): unable to delete virtual dataset, wrong permission name Sep 24, 2020
@codecov-commenter
Copy link

codecov-commenter commented Sep 24, 2020

Codecov Report

Merging #11019 into master will decrease coverage by 4.40%.
The diff coverage is 12.17%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #11019      +/-   ##
==========================================
- Coverage   65.76%   61.35%   -4.41%     
==========================================
  Files         816      817       +1     
  Lines       38381    38523     +142     
  Branches     3606     3621      +15     
==========================================
- Hits        25240    23637    -1603     
- Misses      13033    14700    +1667     
- Partials      108      186      +78     
Flag Coverage Δ
#cypress ?
#javascript 61.77% <ø> (+0.05%) ⬆️
#python 61.11% <12.17%> (-0.27%) ⬇️

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

Impacted Files Coverage Δ
...e8d654_fix_data_access_permissions_for_virtual_.py 0.00% <0.00%> (ø)
superset/datasets/commands/delete.py 93.47% <75.00%> (ø)
superset/views/core.py 73.96% <88.88%> (-0.20%) ⬇️
superset-frontend/src/SqlLab/App.jsx 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/explore/App.jsx 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/dashboard/App.jsx 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/explore/index.jsx 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/dashboard/index.jsx 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/setup/setupColors.js 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/chart/ChartContainer.jsx 0.00% <0.00%> (-100.00%) ⬇️
... and 195 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 ba009b7...61fd2de. Read the comment docs.

and replaces them with the current (correct) permission name
"""
from flask_appbuilder.security.sqla.models import (
ViewMenu,
Copy link
Member

Choose a reason for hiding this comment

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

Should we be referencing concrete model classes in migrations? This migration will likely fail to run in the future should any of their structure change. Ideally, partial impl's, or copies should be defined directly in the migration in order to avoid such a situation. The other option is to roll all of these migrations up into a subset of what we currently have.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I'll probably go for the model copy

…issions_for_virtual_.py

Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com>
@dpgaspar dpgaspar merged commit 5d08a42 into apache:master Sep 29, 2020
@dpgaspar dpgaspar deleted the fix/virtual-dataset-delete branch September 29, 2020 11:33
auxten pushed a commit to auxten/incubator-superset that referenced this pull request Nov 20, 2020
…ache#11019)

* fix(api): unable to delete virtual dataset because of wrong permission name

* Still delete the dataset even when no permission was found

* migration script to fix possible existing faulty permissions on the db

* black

* fix db migration and one more test

* add more comments to the migration script

* freeze a partial schema of the model on the migration step

* fix mig script

* Update superset/migrations/versions/3fbbc6e8d654_fix_data_access_permissions_for_virtual_.py

Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com>

Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com>
@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