Skip to content

refactor: set cascade_backrefs=False for SqlaTable#42213

Open
rusackas wants to merge 3 commits into
masterfrom
refactor/sqla2-cascade-sqlatable
Open

refactor: set cascade_backrefs=False for SqlaTable#42213
rusackas wants to merge 3 commits into
masterfrom
refactor/sqla2-cascade-sqlatable

Conversation

@rusackas

Copy link
Copy Markdown
Member

See #40273

SUMMARY

Enable errors for the "SqlaTable" object is being merged into a Session along the backref cascade path RemovedIn20Warning, and adopt the SQLAlchemy 2.0 behavior for the Database.tables backref.

Constructing SqlaTable(database=...) no longer implicitly merges the new object into the Database's session. All code paths that persist datasets already call session.add() explicitly (dataset commands, uploaders, importers), so no call sites needed changes.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

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

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

🤖 Generated with Claude Code

Enable the pytest error filter for the "'SqlaTable' object is being
merged into a Session along the backref cascade path" RemovedIn20Warning
and adopt the SQLAlchemy 2.0 behavior for the Database.tables backref.

Constructing SqlaTable(database=...) no longer implicitly merges the new
object into the Database's session. All persisting code paths already
add tables to the session explicitly.

See discussion #40273.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@bito-code-review

bito-code-review Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #d9b62e

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 6625a7c..6625a7c
    • 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 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.19%. Comparing base (42a2aed) to head (432fcd1).

Files with missing lines Patch % Lines
superset/examples/generic_loader.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #42213      +/-   ##
==========================================
- Coverage   65.19%   65.19%   -0.01%     
==========================================
  Files        2768     2768              
  Lines      156081   156082       +1     
  Branches    35719    35719              
==========================================
- Hits       101754   101751       -3     
- Misses      52365    52368       +3     
- Partials     1962     1963       +1     
Flag Coverage Δ
hive 38.61% <0.00%> (-0.01%) ⬇️
mysql 57.86% <0.00%> (-0.01%) ⬇️
postgres 57.92% <0.00%> (-0.01%) ⬇️
presto 40.55% <0.00%> (-0.01%) ⬇️
python 59.32% <0.00%> (-0.01%) ⬇️
sqlite 57.53% <0.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.

rusackas and others added 2 commits July 18, 2026 18:03
With cascade_backrefs=False, assigning `tbl.database = database` no
longer implicitly adds a transient SqlaTable to the session. In
generic_loader.py, `fetch_metadata()` and the outer caller each call
`db.session.merge(tbl)`; previously both calls resolved to the same
already-pending object (added via the backref cascade), but now each
merge() creates a separate transient copy, producing two pending
inserts for the same uuid and a uq_tables_uuid violation on the very
first example loaded (which then poisons the session for every
subsequent example in the same transaction).

Also add the missing explicit `db.session.add()` in two
sqla_models_tests.py tests that relied on the same implicit cascade
to persist a freshly constructed SqlaTable before committing/deleting.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The previous commit touched generic_loader.py, so CI pylint now lints
the whole file and flags two pre-existing session.commit() calls that
lack the @transaction decorator. These are example seed-loader scripts,
not command-layer units of work; use the inline disable convention
already established in security/manager.py.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@bito-code-review

bito-code-review Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #4aa873

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 6625a7c..432fcd1
    • superset/examples/generic_loader.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

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant