Skip to content

refactor: do not cascade to TableColumn#42222

Merged
rusackas merged 3 commits into
apache:masterfrom
hy144328:refactor/sqlalchemy-migration-tablecolumn-backref
Jul 21, 2026
Merged

refactor: do not cascade to TableColumn#42222
rusackas merged 3 commits into
apache:masterfrom
hy144328:refactor/sqlalchemy-migration-tablecolumn-backref

Conversation

@hy144328

@hy144328 hy144328 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

See #40273 .

SUMMARY

Disable cascade_backrefs on TableColumn 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 change:backend Requires changing the backend risk:refactor High risk as it involves large refactoring work labels Jul 19, 2026
@bito-code-review

bito-code-review Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #fd5a32

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset/connectors/sqla/models.py - 1
    • Inconsistent relationship configuration · Line 964-964
      The `TableColumn.table` relationship now has `cascade_backrefs=False` (line 964), but the corresponding inverse relationship `SqlaTable.columns` (line 1297-1302) lacks this parameter. This creates asymmetric behavior where one direction of bidirectional assignment will trigger ORM events while the other won't. The `SqlMetric.table` relationship (line 1207-1210) also lacks this parameter, making the inconsistency more apparent. Apply `cascade_backrefs=False` to `SqlaTable.columns` to ensure symmetric backref cascade behavior.
Review Details
  • Files reviewed - 2 · Commit Range: 7050c28..7050c28
    • 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

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.22%. Comparing base (158e321) to head (779cb08).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #42222      +/-   ##
==========================================
- Coverage   65.22%   65.22%   -0.01%     
==========================================
  Files        2768     2768              
  Lines      156280   156285       +5     
  Branches    35774    35774              
==========================================
+ Hits       101933   101936       +3     
- Misses      52382    52384       +2     
  Partials     1965     1965              
Flag Coverage Δ
hive 38.60% <0.00%> (-0.01%) ⬇️
mysql 57.87% <100.00%> (+<0.01%) ⬆️
postgres 57.92% <100.00%> (+<0.01%) ⬆️
presto 40.54% <57.14%> (+<0.01%) ⬆️
python 59.33% <100.00%> (+<0.01%) ⬆️
sqlite 57.53% <100.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.

Comment thread superset/connectors/sqla/models.py
@bito-code-review

Copy link
Copy Markdown
Contributor

The flagged issue is correct. Disabling cascade_backrefs on the TableColumn.table relationship prevents SQLAlchemy from automatically adding new TableColumn objects to the session when they are associated with a SqlaTable via the table attribute. To resolve this, you should either remove cascade_backrefs=False to restore default behavior, or ensure that every newly created TableColumn is explicitly added to the session using session.add(column) before flushing.

superset/connectors/sqla/models.py

table: Mapped["SqlaTable"] = relationship(
        "SqlaTable",
        back_populates="columns",
        # cascade_backrefs=False,  <-- Remove this line to restore default behavior
    )

@hy144328
hy144328 force-pushed the refactor/sqlalchemy-migration-tablecolumn-backref branch from 7050c28 to 171e144 Compare July 19, 2026 23:34
@bito-code-review

bito-code-review Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #9ba9f8

Actionable Suggestions - 0
Additional Suggestions - 1
  • pytest.ini - 1
    • Inconsistent warning filter pattern · Line 36-36
      Enabling only `TableColumn` for session-merge warning enforcement creates inconsistency with the commented-out pattern on lines 32-35 and 37. If TableColumn objects are being incorrectly merged into Sessions, this change is correct, but the rationale should be documented to prevent confusion during future SQLAlchemy 2.0 migration work.
Review Details
  • Files reviewed - 2 · Commit Range: 171e144..171e144
    • 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

@rusackas

Copy link
Copy Markdown
Member

Rebased, resolved the usual conflict with these, and CI is running :)

@netlify

netlify Bot commented Jul 20, 2026

Copy link
Copy Markdown

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 6f9e4f0
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a5e839ddd8b020008d9d85e
😎 Deploy Preview https://deploy-preview-42222--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.

Comment thread tests/integration_tests/sqla_models_tests.py
@sadpandajoe

Copy link
Copy Markdown
Member

@hy144328 thanks for the PR, mind adding more details to your PR description?

@hy144328
hy144328 marked this pull request as draft July 20, 2026 18:22
@hy144328
hy144328 force-pushed the refactor/sqlalchemy-migration-tablecolumn-backref branch from c9d8724 to 718a10d Compare July 20, 2026 19:58
@hy144328
hy144328 force-pushed the refactor/sqlalchemy-migration-tablecolumn-backref branch from 718a10d to 6f9e4f0 Compare July 20, 2026 20:22
@hy144328
hy144328 force-pushed the refactor/sqlalchemy-migration-tablecolumn-backref branch from 6f9e4f0 to 575416a Compare July 20, 2026 21:04
@hy144328
hy144328 marked this pull request as ready for review July 20, 2026 22:19
@bito-code-review

bito-code-review Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #c2b2f8

Actionable Suggestions - 0
Additional Suggestions - 3
  • tests/integration_tests/db_engine_specs/bigquery_tests.py - 1
    • Variable shadowing import · Line 319-320
      Local variable `column` shadows the `column` function imported from `sqlalchemy` on line 22, creating semantic ambiguity within the test method scope. Per project style rules, local variables should not shadow module-level imports.
  • superset/connectors/sqla/models.py - 2
    • Missing documentation for SQLAlchemy 2.0 fix · Line 964-964
      The `cascade_backrefs=False` at line 964 lacks the documentation comment that exists at line 1375 for an identical pattern. Without context, future maintainers cannot understand why this parameter is needed or that it must be removed when upgrading to SQLAlchemy 2.0.
    • Missing documentation for SQLAlchemy 2.0 fix · Line 1301-1301
      The `cascade_backrefs=False` at line 1301 lacks the documentation comment that exists at line 1375 for an identical pattern. Without context, future maintainers cannot understand why this parameter is needed or that it must be removed when upgrading to SQLAlchemy 2.0.
Review Details
  • Files reviewed - 13 · Commit Range: 08c6a0d..779cb08
    • pytest.ini
    • superset/commands/dataset/duplicate.py
    • superset/connectors/sqla/models.py
    • superset/examples/birth_names.py
    • tests/integration_tests/conftest.py
    • tests/integration_tests/datasets/api_tests.py
    • tests/integration_tests/datasource_tests.py
    • tests/integration_tests/db_engine_specs/base_engine_spec_tests.py
    • tests/integration_tests/db_engine_specs/bigquery_tests.py
    • tests/integration_tests/db_engine_specs/datastore_tests.py
    • tests/integration_tests/fixtures/datasource.py
    • tests/integration_tests/import_export_tests.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

@rusackas rusackas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Went through the TableColumn call sites and the two Bito findings, both check out as non-issues given the current code (replies inline). CI's green across postgres/mysql/sqlite. LGTM.

@rusackas
rusackas merged commit 6c58afe into apache:master Jul 21, 2026
92 of 95 checks passed
@hy144328
hy144328 deleted the refactor/sqlalchemy-migration-tablecolumn-backref branch July 21, 2026 18:50
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 risk:refactor High risk as it involves large refactoring work size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants