Skip to content

refactor: set cascade_backrefs=False for SavedQuery#42212

Merged
rusackas merged 1 commit into
masterfrom
refactor/sqla2-cascade-savedquery
Jul 20, 2026
Merged

refactor: set cascade_backrefs=False for SavedQuery#42212
rusackas merged 1 commit into
masterfrom
refactor/sqla2-cascade-savedquery

Conversation

@rusackas

Copy link
Copy Markdown
Member

See #40273

SUMMARY

Enable errors for the "SavedQuery" object is being merged into a Session along the backref cascade path RemovedIn20Warning, and adopt the SQLAlchemy 2.0 behavior for both SavedQuery backrefs (User.saved_queries and Database.saved_queries).

Constructing SavedQuery(database=...) or SavedQuery(user=...) no longer implicitly merges the new object into the parent's session. All code paths that persist saved queries already call session.add() explicitly, 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

@bito-code-review

bito-code-review Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #e52282

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: da88be6..da88be6
    • pytest.ini
    • superset/models/sql_lab.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

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.21%. Comparing base (158e321) to head (52d11e3).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #42212      +/-   ##
==========================================
- Coverage   65.22%   65.21%   -0.01%     
==========================================
  Files        2768     2768              
  Lines      156280   156280              
  Branches    35774    35774              
==========================================
- Hits       101930   101916      -14     
- Misses      52384    52398      +14     
  Partials     1966     1966              
Flag Coverage Δ
hive 38.60% <ø> (ø)
mysql 57.86% <ø> (ø)
postgres 57.92% <ø> (ø)
presto 40.54% <ø> (ø)
python 59.32% <ø> (ø)
sqlite 57.52% <ø> (ø)
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

Copy link
Copy Markdown
Contributor

Looks great.
It is noteworthy that the PR does not manually add SavedQuery to the session anywhere after the removal of cascade_backrefs.
I have double-checked all 13 or so references to the SavedQuery() constructor.
They are already all followed by a db.session.add().
So it is as simple as it looks, and I think the PR is good to go.

@hy144328 hy144328 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.

Accidentally put my review down as a comment. #42212 (comment)
Nevertheless, I think good to go!

@rusackas
rusackas force-pushed the refactor/sqla2-cascade-savedquery branch from da88be6 to c8ec89e Compare July 20, 2026 18:43
@rusackas

Copy link
Copy Markdown
Member Author

Thanks for double-checking all the SavedQuery() call sites, @hy144328! Appreciate it.

Enable the pytest error filter for the "'SavedQuery' object is being
merged into a Session along the backref cascade path" RemovedIn20Warning
and adopt the SQLAlchemy 2.0 behavior for both SavedQuery backrefs
(User.saved_queries and Database.saved_queries).

Constructing SavedQuery(database=...) or SavedQuery(user=...) no longer
implicitly merges the new object into the parent's session. All
persisting code paths already add saved queries explicitly.

See discussion #40273.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@rusackas
rusackas force-pushed the refactor/sqla2-cascade-savedquery branch from c8ec89e to 52d11e3 Compare July 20, 2026 19:06
@bito-code-review

bito-code-review Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #3404c2

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 52d11e3..52d11e3
    • pytest.ini
    • superset/models/sql_lab.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 merged commit abd6dc8 into master Jul 20, 2026
59 checks passed
@rusackas
rusackas deleted the refactor/sqla2-cascade-savedquery branch July 20, 2026 22:37
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.

3 participants