Skip to content

refactor: do not cascade to SqlMetric#42221

Open
hy144328 wants to merge 3 commits into
apache:masterfrom
hy144328:refactor/sqlalchemy-migration-sqlmetric-backref
Open

refactor: do not cascade to SqlMetric#42221
hy144328 wants to merge 3 commits into
apache:masterfrom
hy144328:refactor/sqlalchemy-migration-sqlmetric-backref

Conversation

@hy144328

@hy144328 hy144328 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

See #40273 .

SUMMARY

Disable cascade_backrefs on SqlMetric because it is deprecated in Airflow 2.
Manually add objects to session that were previously added automatically.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

Unit tests:

$ SQLALCHEMY_WARN_20=1 python3 -m pytest tests/unit_tests/

Integration tests via CI.

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

@dosubot dosubot Bot added the change:backend Requires changing the backend label Jul 19, 2026
@bito-code-review

bito-code-review Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #e81c94

Actionable Suggestions - 0
Additional Suggestions - 2
  • superset/connectors/sqla/models.py - 2
    • Inconsistent relationship config · Line 1209-1209
      The fix correctly addresses the RemovedIn20Warning. However, `TableColumn` (line 961-964) has an identical back_populates relationship to SqlaTable without this setting. If both classes have the same exposure to the warning, TableColumn should also have `cascade_backrefs=False` for consistency.
    • Missing doc comment for ORM behavior change · Line 1209-1209
      No explanatory comment accompanies the `cascade_backrefs=False` parameter. Given this is a SQLAlchemy behavior modification that affects cascade semantics, a brief comment would help future maintainers understand the intent (e.g., SQLAlchemy 2.0 preparation, avoiding implicit backref cascades, or addressing a specific bug).
Review Details
  • Files reviewed - 2 · Commit Range: 231b9aa..231b9aa
    • pytest.ini
    • superset/connectors/sqla/models.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@codecov

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.19%. Comparing base (36dbff0) to head (e5df73d).
⚠️ Report is 19 commits behind head on master.

Files with missing lines Patch % Lines
superset/examples/world_bank.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #42221      +/-   ##
==========================================
- Coverage   65.19%   65.19%   -0.01%     
==========================================
  Files        2768     2768              
  Lines      156081   156086       +5     
  Branches    35719    35718       -1     
==========================================
+ Hits       101754   101757       +3     
- Misses      52365    52367       +2     
  Partials     1962     1962              
Flag Coverage Δ
hive 38.61% <0.00%> (-0.01%) ⬇️
mysql 57.87% <70.00%> (+<0.01%) ⬆️
postgres 57.92% <70.00%> (+<0.01%) ⬆️
presto 40.55% <40.00%> (+<0.01%) ⬆️
python 59.33% <70.00%> (+<0.01%) ⬆️
sqlite 57.54% <70.00%> (+<0.01%) ⬆️
unit 100.00% <ø> (ø)

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

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hy144328
hy144328 force-pushed the refactor/sqlalchemy-migration-sqlmetric-backref branch from 231b9aa to 6f3fb56 Compare July 19, 2026 23:31
@bito-code-review

bito-code-review Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #1b66af

Actionable Suggestions - 0
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • superset/connectors/sqla/models.py - 1
Review Details
  • Files reviewed - 2 · Commit Range: 6f3fb56..6f3fb56
    • pytest.ini
    • superset/connectors/sqla/models.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@netlify

netlify Bot commented Jul 20, 2026

Copy link
Copy Markdown

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 7831082
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a5e14d87e8a3d00082c4f6c
😎 Deploy Preview https://deploy-preview-42221--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@bito-code-review

bito-code-review Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #63e27a

Actionable Suggestions - 0
Review Details
  • Files reviewed - 9 · Commit Range: 6f3fb56..7831082
    • superset/commands/dataset/duplicate.py
    • superset/connectors/sqla/models.py
    • superset/examples/birth_names.py
    • superset/examples/world_bank.py
    • tests/integration_tests/conftest.py
    • tests/integration_tests/datasets/api_tests.py
    • tests/integration_tests/fixtures/energy_dashboard.py
    • tests/integration_tests/sqla_models_tests.py
    • tests/unit_tests/datasets/commands/export_test.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@hy144328
hy144328 force-pushed the refactor/sqlalchemy-migration-sqlmetric-backref branch from 7831082 to e5df73d Compare July 20, 2026 16:04
@sadpandajoe
sadpandajoe requested a review from rusackas July 20, 2026 17:24
@sadpandajoe

Copy link
Copy Markdown
Member

@hy144328 thanks for the PR. Mind adding more details in your PR description.

@bito-code-review bito-code-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review Agent Run #5f6135

Actionable Suggestions - 1
  • tests/integration_tests/datasets/api_tests.py - 1
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • superset/connectors/sqla/models.py - 1
Review Details
  • Files reviewed - 9 · Commit Range: 6f3fb56..e5df73d
    • pytest.ini
    • superset/commands/dataset/duplicate.py
    • superset/connectors/sqla/models.py
    • superset/examples/birth_names.py
    • superset/examples/world_bank.py
    • tests/integration_tests/conftest.py
    • tests/integration_tests/datasets/api_tests.py
    • tests/integration_tests/fixtures/energy_dashboard.py
    • tests/integration_tests/sqla_models_tests.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

if columns:
table.columns = columns
if metrics:
db.session.add_all(metrics)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Redundant session.add_all call

The explicit db.session.add_all(metrics) is semantically dead code. SQLAlchemy's cascade="all" includes save-update cascade, which automatically persists child SqlMetric objects when db.session.add(table) is called on line 128. This creates inconsistent treatment compared to how columns is handled on line 124, which correctly relies solely on cascade. Remove this line to maintain consistency and reflect correct understanding of ORM behavior.

Code Review Run #5f6135


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

cascade_backrefs is set to False.
TableColumn is handled in a separate PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The suggestion to remove db.session.add_all(metrics) is technically correct if the SqlMetric relationship is configured with cascade="all, delete-orphan" or similar save-update cascades. In such cases, adding the parent table object to the session automatically persists the associated metrics collection, making the explicit add_all call redundant. Removing it improves consistency with how the columns collection is handled in the same function.

tests/integration_tests/datasets/api_tests.py

if columns:
            table.columns = columns
        if metrics:
            db.session.add_all(metrics)

@rusackas

Copy link
Copy Markdown
Member

Thanks for this, Hans. Bito's thread on api_tests.py:126 is still open, and your reply about cascade_backrefs doesn't quite answer whether db.session.add_all(metrics) is redundant given table.metrics = metrics then db.session.add(table) should cascade-save them anyway. Mind resolving that one way or another?

Also, sadpandajoe's ask above for more detail in the PR description is still open, would help given this touches cascade semantics in a few places, and we do refer back to PR descriptions in various places for history.

Looks like it needs a rebase too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:backend Requires changing the backend size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants