Skip to content

fix(deps): add temporary SQLAlchemy 1.4 compatibility lane - #43263

Closed
aminghadersohi wants to merge 1 commit into
masterfrom
sqlalchemy-dual-compat
Closed

fix(deps): add temporary SQLAlchemy 1.4 compatibility lane#43263
aminghadersohi wants to merge 1 commit into
masterfrom
sqlalchemy-dual-compat

Conversation

@aminghadersohi

Copy link
Copy Markdown
Contributor

SUMMARY

Adds a temporary, tested SQLAlchemy 1.4 compatibility lane for downstreams such as Preset Shell without reverting the SQLAlchemy 2 upgrade from #42803.

The normal OSS lock files and install path remain on SQLAlchemy 2.0.51 with Flask-SQLAlchemy 3.1.1. Downstreams using the bridge must constrain both SQLAlchemy 1.4.54 and Flask-SQLAlchemy 2.5.1 together, using requirements/sqlalchemy14.txt as the reference pair.

Python package metadata cannot express correlated dependency alternatives ("SQLAlchemy 1.4 + Flask-SQLAlchemy 2.5" or "SQLAlchemy 2 + Flask-SQLAlchemy 3.1"). The widened bounds therefore expose the union needed by a downstream constraints file; arbitrary cross-pair combinations are not supported. Excluding Flask-SQLAlchemy 3.0.x, keeping the generated OSS requirements on the modern pair, and validating the exact legacy pair in CI avoids presenting an accidental third supported lane.

Runtime compatibility remains narrow:

  • use the transaction API shared by SQLAlchemy 1.4 and 2.x when rolling back the connection health check;
  • make a SQL compilation assertion insensitive to version-specific projection ordering and redundant parentheses while continuing to verify its permission predicates;
  • retain all other SQLAlchemy 2 migration work and post-feat: bump SQLAlchemy to 2.0 and flask-sqlalchemy to 3.1.1 #42803 session/SAVEPOINT/MCP isolation fixes.

The commonly tested bigquery, druid, duckdb, fastmcp, gevent, gsheets, mysql, postgres, presto, prophet, trino, and thumbnails extras are available in both lanes. The selected dremio, exasol, firebird, redshift, and risingwave driver lines are explicitly documented as SQLAlchemy 2-only; their OSS defaults are not silently downgraded. Other extras are not covered by the legacy lane and require downstream validation.

This is intended as a temporary migration bridge. Once Preset Shell and other known downstreams have moved to SQLAlchemy 2, remove the paired constraints, widened lower bounds, compatibility code, documentation, and legacy CI job together. #43260 remains the broader full-rollback alternative; this PR does not close it.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Not applicable; dependency, backend compatibility, and CI changes only.

TESTING INSTRUCTIONS

Regenerated dependency artifacts with repository tooling; the generated files were unchanged and continue to pin SQLAlchemy 2.0.51 / Flask-SQLAlchemy 3.1.1:

./scripts/uv-pip-compile.sh

Validated dependencies and ran the CI-selected app initialization, ORM/session/engine, migration, SAVEPOINT, MCP isolation, DuckDB, and SQL Lab tests on both exact stacks:

SQLAlchemy 2.0.51 + Flask-SQLAlchemy 3.1.1: 403 passed, 4 skipped
SQLAlchemy 1.4.54 + Flask-SQLAlchemy 2.5.1: 403 passed, 4 skipped
uv pip check: passed on both stacks

Ran a full empty-SQLite superset db upgrade successfully on both stacks.

PRE_COMMIT_HOME=/tmp/pre-commit-cache pre-commit run
# passed

The sqlalchemy14-compatibility CI job installs the existing development lock, replaces only the two packages from requirements/sqlalchemy14.txt, runs uv pip check, and executes the targeted suite. The existing required SA2 unit-test matrix is unchanged; its stable required anchor now also requires the compatibility lane.

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

Comment thread superset/utils/core.py
Comment on lines +833 to +834
if transaction := connection.get_transaction():
transaction.rollback()

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.

Suggestion: In the invalidated-connection path, the failed SELECT 1 has already started a transaction under SQLAlchemy 2.x. Retrying connection.scalar(select(1)) before rolling back leaves the invalidated connection in an active transaction, so SQLAlchemy can raise PendingRollbackError instead of reconnecting. Roll back the existing transaction before the retry, then roll back any transaction created by the retry. [state/lifecycle]

Severity Level: Major ⚠️
- ❌ Stale pooled connections can fail health-check recovery.
- ⚠️ Requests requiring `db.engine` may receive connection errors.
- ⚠️ Transient database disconnects may become application-level failures.

Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/utils/core.py
**Line:** 833:834
**Comment:**
	*State Lifecycle: In the invalidated-connection path, the failed `SELECT 1` has already started a transaction under SQLAlchemy 2.x. Retrying `connection.scalar(select(1))` before rolling back leaves the invalidated connection in an active transaction, so SQLAlchemy can raise `PendingRollbackError` instead of reconnecting. Roll back the existing transaction before the retry, then roll back any transaction created by the retry.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Comment on lines +123 to +125
assert "FROM dbs LEFT OUTER JOIN ssh_tunnels" in sql
assert "'[my_db].(id:42)', '[my_other_db].(id:43)'" in sql
assert "dbs.database_name IN ('my_db', 'my_other_db', 'third_db')" in sql

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.

Suggestion: The assertions only verify that each predicate appears somewhere in the SQL, not that the permission predicates are combined with the required OR grouping. A regression changing the authorization expression to AND, or otherwise altering its boolean grouping, would still pass all three assertions while returning an incorrect set of accessible databases. Assert the complete predicate structure or execute the query against representative rows. [incomplete implementation]

Severity Level: Major ⚠️
- ⚠️ Database listing authorization regressions remain undetected.
- ⚠️ Report APIs apply `DatabaseFilter` to database relations.
- ⚠️ Saved-query database selectors use the same filter.

Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/unit_tests/databases/filters_test.py
**Line:** 123:125
**Comment:**
	*Incomplete Implementation: The assertions only verify that each predicate appears somewhere in the SQL, not that the permission predicates are combined with the required `OR` grouping. A regression changing the authorization expression to `AND`, or otherwise altering its boolean grouping, would still pass all three assertions while returning an incorrect set of accessible databases. Assert the complete predicate structure or execute the query against representative rows.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@bito-code-review

Copy link
Copy Markdown
Contributor

Code Review Agent Run #edce83

Actionable Suggestions - 0
Review Details
  • Files reviewed - 6 · Commit Range: 6c79b15..6c79b15
    • pyproject.toml
    • requirements/sqlalchemy14.txt
    • superset-core/pyproject.toml
    • superset/utils/core.py
    • tests/unit_tests/databases/filters_test.py
    • tests/unit_tests/utils/test_core.py
  • Files skipped - 2
    • .github/workflows/superset-python-unittest.yml - Reason: Filter setting
    • requirements/README.md - Reason: Filter setting
  • 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 Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.06%. Comparing base (1991e3f) to head (6c79b15).

Files with missing lines Patch % Lines
superset/utils/core.py 25.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #43263      +/-   ##
==========================================
- Coverage   66.65%   66.06%   -0.59%     
==========================================
  Files        2874     2874              
  Lines      163781   163783       +2     
  Branches    37798    37800       +2     
==========================================
- Hits       109165   108207     -958     
- Misses      52477    53434     +957     
- Partials     2139     2142       +3     
Flag Coverage Δ
hive 38.13% <25.00%> (-0.01%) ⬇️
mysql ?
postgres 57.86% <25.00%> (-0.01%) ⬇️
presto 40.08% <25.00%> (-0.01%) ⬇️
python 58.06% <25.00%> (-1.19%) ⬇️
sqlite 57.50% <25.00%> (-0.01%) ⬇️
unit ?

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.

@aminghadersohi
aminghadersohi marked this pull request as draft August 17, 2026 17:53
@aminghadersohi

Copy link
Copy Markdown
Contributor Author

Closing this in favor of fixing forward on SQLAlchemy 2.0. We are keeping the SQLAlchemy 2 upgrade, updating and qualifying the downstream driver fleet, adding a machine-readable driver inventory/drift gate, and introducing real runtime coverage for materially used connectors rather than retaining the rollback path. The first Shell implementation is preset-io/superset-shell#4845, with follow-up work planned for Athena qualification, DataFusion restoration, customer-usage prioritization, and permanent connector canaries.

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

Labels

github_actions Pull requests that update GitHub Actions code size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant