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(dao): Add explicit ON DELETE CASCADE for ownership #24628

Merged

Conversation

john-bodley
Copy link
Member

SUMMARY

Per SIP-92 Proposal for restructuring the Python code base #24331 organized all the DAOs to be housed within a shared folder—the result of which highlighted numerous inconsistencies, repetition, and inefficiencies.

This PR is somewhat akin to #24488 where explicit ON DELETE CASCADE operations are set for the ownership associations.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

CI.

ADDITIONAL INFORMATION

  • Has associated issue: [SIP-92] Proposal for restructuring the Python code base #20630
  • 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: Takes ~ 1 minute for Airbnb's instance w/o load.
  • Introduces new feature or API
  • Removes existing feature or API

item_ids = [item.id for item in get_iterable(items)]
try:
# Clean owners secondary table
report_schedules = (
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'm not really sure why the reports were refetched as opposed to using the items provides. Note after removing the need to remove the owners this logic simply reduced to the BaseDAO.delete method and thus is unnecessary.

@@ -535,7 +535,6 @@ def create_dashboard(slices: list[Slice]) -> Dashboard:
dash = db.session.query(Dashboard).filter_by(slug="births").first()
if not dash:
dash = Dashboard()
dash.owners = []
Copy link
Member Author

Choose a reason for hiding this comment

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

No need to initialize this.


# revision identifiers, used by Alembic.
revision = "6fbe660cac39"
down_revision = "90139bf715e4"

import sqlalchemy as sa
Copy link
Member Author

Choose a reason for hiding this comment

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

Same logic as before, but using the more generalized shared constraints logic.

@@ -53,12 +53,12 @@
Model.metadata, # pylint: disable=no-member
sa.Column(
"table_id",
sa.ForeignKey("sl_tables.id", ondelete="cascade"),
sa.ForeignKey("sl_tables.id", ondelete="CASCADE"),
Copy link
Member Author

Choose a reason for hiding this comment

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

Using uppercase for consistency.

@@ -282,8 +282,6 @@ def test_import_v1_chart(self, sm_g, utils_g):

assert chart.owners == [admin]

chart.owners = []
database.owners = []
Copy link
Member Author

Choose a reason for hiding this comment

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

Databases don't have owners so this line was a red herring.

@@ -146,9 +146,6 @@ def test_import_assets(self):

assert dashboard.owners == [self.user]

dashboard.owners = []
chart.owners = []
database.owners = []
Copy link
Member Author

Choose a reason for hiding this comment

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

See above.

dashboard.owners = []

chart.owners = []
database.owners = []
Copy link
Member Author

Choose a reason for hiding this comment

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

See above.

@@ -573,9 +573,6 @@ def test_import_v1_dashboard(self, sm_g, utils_g):

assert dashboard.owners == [admin]

dashboard.owners = []
chart.owners = []
database.owners = []
Copy link
Member Author

Choose a reason for hiding this comment

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

See above.

@@ -400,7 +400,6 @@ def test_import_v1_dataset(self, sm_g, utils_g):
assert column.description is None
assert column.python_date_format is None

dataset.database.owners = []
Copy link
Member Author

Choose a reason for hiding this comment

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

See above.

@@ -528,7 +527,6 @@ def test_import_v1_dataset_existing_database(self, mock_g):
)
assert len(database.tables) == 1

database.owners = []
Copy link
Member Author

Choose a reason for hiding this comment

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

See above.

@john-bodley john-bodley force-pushed the john-bodley--dao-owners-ondelete-cascade branch from 38ca4e8 to 8e2b3d8 Compare July 8, 2023 02:58
@john-bodley john-bodley marked this pull request as ready for review July 8, 2023 02:59
@john-bodley john-bodley requested a review from a team as a code owner July 8, 2023 02:59
@codecov
Copy link

codecov bot commented Jul 8, 2023

Codecov Report

Merging #24628 (273b32d) into master (c53b249) will increase coverage by 0.08%.
The diff coverage is 31.25%.

❗ Current head 273b32d differs from pull request most recent head 7c045a5. Consider uploading reports for the commit 7c045a5 to get more accurate results

@@            Coverage Diff             @@
##           master   #24628      +/-   ##
==========================================
+ Coverage   68.97%   69.05%   +0.08%     
==========================================
  Files        1907     1908       +1     
  Lines       74153    74168      +15     
  Branches     8182     8177       -5     
==========================================
+ Hits        51148    51219      +71     
+ Misses      20882    20829      -53     
+ Partials     2123     2120       -3     
Flag Coverage Δ
hive 54.12% <20.58%> (?)
mysql 79.42% <35.29%> (?)
postgres 79.51% <35.29%> (-0.05%) ⬇️
presto 54.02% <20.58%> (-0.02%) ⬇️
python 83.49% <35.29%> (+0.16%) ⬆️
sqlite 78.07% <35.29%> (-0.05%) ⬇️
unit 54.81% <20.58%> (-0.02%) ⬇️

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

Impacted Files Coverage Δ
...hart-echarts/src/MixedTimeseries/transformProps.ts 0.78% <ø> (ø)
superset-frontend/src/components/Icons/Icon.tsx 0.00% <ø> (ø)
...Filters/FilterBar/FilterControls/FilterControl.tsx 27.69% <0.00%> (-0.44%) ⬇️
...veFilters/FilterBar/FilterControls/FilterValue.tsx 5.76% <ø> (+0.10%) ⬆️
...tersConfigModal/FiltersConfigForm/DefaultValue.tsx 9.09% <0.00%> (ø)
...mponents/nativeFilters/FiltersConfigModal/utils.ts 46.96% <0.00%> (ø)
...nd/src/dashboard/components/nativeFilters/state.ts 64.28% <ø> (ø)
...perset-frontend/src/dashboard/util/crossFilters.ts 75.00% <ø> (ø)
.../src/explore/components/ControlPanelsContainer.tsx 69.76% <0.00%> (ø)
...rset-frontend/src/explore/components/SaveModal.tsx 35.13% <ø> (+0.04%) ⬆️
... and 26 more

... and 8 files with indirect coverage changes

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

@john-bodley john-bodley force-pushed the john-bodley--dao-owners-ondelete-cascade branch from 8e2b3d8 to a2f826b Compare July 8, 2023 05:39

# revision identifiers, used by Alembic.
revision = "6d05b0a70c89"
down_revision = "240d23c7f86f"
Copy link
Contributor

Choose a reason for hiding this comment

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

@john-bodley Use the latest f92a3124dd66 revision
Also update Create Date in filename in order to have this file after f92a3124dd66 in migrations/versions folder.

Copy link
Member Author

Choose a reason for hiding this comment

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

@EugeneTorap I've updated the SHA. AFAIK we typically don't update the date associated with the filename, i.e., there's no guarantee that these revisions are in chronological order, i.e., they merely serves as a guide. cc @craig-rueda for guidance.

Copy link
Member

Choose a reason for hiding this comment

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

I would say that updating the filename is fine. Ideally the filename would be somewhat close to the date that the PR is merged as to keep things somewhat sorted.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

@craig-rueda craig-rueda left a comment

Choose a reason for hiding this comment

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

LGTM

…_for_owners_references.py to 2023-07-11_15-51_6d05b0a70c89_add_on_delete_cascade_for_owners_references.py
@john-bodley john-bodley merged commit ae00489 into apache:master Jul 11, 2023
29 checks passed
@john-bodley john-bodley deleted the john-bodley--dao-owners-ondelete-cascade branch July 11, 2023 18:39
@michael-s-molina michael-s-molina added the v3.0 Label added by the release manager to track PRs to be included in the 3.0 branch label Jul 11, 2023
@mistercrunch mistercrunch added 🍒 3.0.0 🍒 3.0.1 🍒 3.0.2 🍒 3.0.3 🍒 3.0.4 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 3.1.0 labels Mar 8, 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 v3.0 Label added by the release manager to track PRs to be included in the 3.0 branch 🍒 3.0.0 🍒 3.0.1 🍒 3.0.2 🍒 3.0.3 🍒 3.0.4 🚢 3.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants