Skip to content

refactor: update SQLAlchemy select() syntax to 2.0 - #40276

Merged
rusackas merged 7 commits into
apache:masterfrom
hy144328:refactor/sqlalchemy-migration-select-statements
Jun 18, 2026
Merged

rusackas merged 7 commits into
apache:masterfrom
hy144328:refactor/sqlalchemy-migration-select-statements

Conversation

@hy144328

@hy144328 hy144328 commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

See #40273 .
Depends on #40274 .

SUMMARY

Enable errors for deprecated sqlalchemy.select() syntax, and fix them all.

In addition to fixing all broken tests, I manually went through all results of git grep select(.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

No errors:

$ 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

@dosubot dosubot Bot added change:backend Requires changing the backend risk:refactor High risk as it involves large refactoring work labels May 19, 2026
@bito-code-review

bito-code-review Bot commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #ff1d28

Actionable Suggestions - 0
Filtered by Review Rules

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

  • tests/unit_tests/db_engine_specs/test_bigquery.py - 1
    • Correctness: select() argument unpacking · Line 83-83
Review Details
  • Files reviewed - 15 · Commit Range: 26b7357..4d63925
    • pytest.ini
    • superset/commands/importers/v1/utils.py
    • superset/common/tags.py
    • superset/connectors/sqla/models.py
    • superset/db_engine_specs/base.py
    • superset/extensions/metadb.py
    • superset/migrations/versions/2020-01-08_01-17_e96dbf2cfef0_datasource_cluster_fk.py
    • superset/migrations/versions/2020-04-24_10-46_e557699a813e_add_tables_relation_to_row_level_.py
    • superset/migrations/versions/2022-04-01_14-38_a9422eeaae74_new_dataset_models_take_2.py
    • superset/migrations/versions/2024-01-17_13-09_96164e3017c6_tagged_object_unique_constraint.py
    • superset/models/helpers.py
    • superset/utils/core.py
    • tests/unit_tests/db_engine_specs/test_bigquery.py
    • tests/unit_tests/db_engine_specs/test_datastore.py
    • tests/unit_tests/db_engine_specs/test_mssql.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ 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 [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@github-actions github-actions Bot added the risk:db-migration PRs that require a DB migration label May 19, 2026
@netlify

netlify Bot commented May 19, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

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

Copilot AI 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.

Pull request overview

This PR updates the codebase to use SQLAlchemy’s 1.4/2.0-style select() calling convention (positional columns instead of legacy list-based usage), and adjusts pytest warning configuration to surface/deprecate specific SQLAlchemy 2.0 warnings during local runs.

Changes:

  • Refactor legacy select([ ... ]) / select(list_of_cols) calls to select(col1, col2, ...) or select(*cols).
  • Update core query construction sites (engine specs, helpers, metadb, import utils) and unit tests accordingly.
  • Replace -p no:warnings with filterwarnings rules and error on the legacy select() calling style.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/unit_tests/db_engine_specs/test_mssql.py Updates select() usage in MSSQL engine spec unit test.
tests/unit_tests/db_engine_specs/test_datastore.py Updates select(*fields) usage in Datastore engine spec unit test.
tests/unit_tests/db_engine_specs/test_bigquery.py Updates select(*fields) usage in BigQuery engine spec unit test.
superset/utils/core.py Updates connection ping to select(1) in pessimistic connection handling.
superset/models/helpers.py Refactors multiple query builders to SQLAlchemy 2.0-style select() calls.
superset/migrations/versions/2024-01-17_13-09_96164e3017c6_tagged_object_unique_constraint.py Refactors select() usage in migration cleanup subquery and delete query.
superset/migrations/versions/2022-04-01_14-38_a9422eeaae74_new_dataset_models_take_2.py Refactors many select() calls used for insert_from_select migration logic.
superset/migrations/versions/2020-04-24_10-46_e557699a813e_add_tables_relation_to_row_level_.py Refactors select() usage in upgrade/downgrade migration logic.
superset/migrations/versions/2020-01-08_01-17_e96dbf2cfef0_datasource_cluster_fk.py Refactors select() usage in datasource/cluster FK migration.
superset/extensions/metadb.py Refactors table/count selects to SQLAlchemy 2.0-style select().
superset/db_engine_specs/base.py Refactors select_star() query construction to avoid legacy select(list) usage.
superset/connectors/sqla/models.py Refactors ad-hoc type probe query select() calls.
superset/common/tags.py Refactors tag backfill queries to SQLAlchemy 2.0-style select() calls.
superset/commands/importers/v1/utils.py Refactors relationship lookup query to SQLAlchemy 2.0-style select().
pytest.ini Switches from -p no:warnings to filterwarnings and errors on legacy select() calling style.

Comment thread pytest.ini Resolved
@codecov

codecov Bot commented May 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 29.41176% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.26%. Comparing base (09b4bc5) to head (3ba3ce7).
⚠️ Report is 19 commits behind head on master.

Files with missing lines Patch % Lines
superset/models/helpers.py 25.00% 6 Missing ⚠️
superset/common/tags.py 0.00% 2 Missing ⚠️
superset/extensions/metadb.py 0.00% 2 Missing ⚠️
superset/connectors/sqla/models.py 50.00% 1 Missing ⚠️
superset/utils/core.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40276      +/-   ##
==========================================
- Coverage   64.26%   64.26%   -0.01%     
==========================================
  Files        2660     2660              
  Lines      144778   144785       +7     
  Branches    33381    33383       +2     
==========================================
- Hits        93045    93043       -2     
- Misses      50084    50089       +5     
- Partials     1649     1653       +4     
Flag Coverage Δ
hive 39.35% <5.88%> (-0.01%) ⬇️
mysql 58.07% <23.52%> (-0.01%) ⬇️
postgres 58.13% <29.41%> (-0.01%) ⬇️
presto 40.92% <11.76%> (-0.01%) ⬇️
python 59.59% <29.41%> (-0.01%) ⬇️
sqlite 57.76% <23.52%> (-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
rusackas force-pushed the refactor/sqlalchemy-migration-select-statements branch from a81f704 to 821bef9 Compare June 15, 2026 15:58
@rusackas

Copy link
Copy Markdown
Member

Just rebased the branch, but this is generally looking ready to approve to my eyes. Would love to have the bot comments addressed, but otherwise just waiting on a second opinion from @villebro @michael-s-molina @betodealmeida @dpgaspar

@bito-code-review

bito-code-review Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #ada842

Actionable Suggestions - 0
Filtered by Review Rules

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

  • pytest.ini - 1
  • tests/unit_tests/db_engine_specs/test_datastore.py - 1
Review Details
  • Files reviewed - 15 · Commit Range: 1c70dca..df29e18
    • pytest.ini
    • superset/commands/importers/v1/utils.py
    • superset/common/tags.py
    • superset/connectors/sqla/models.py
    • superset/db_engine_specs/base.py
    • superset/extensions/metadb.py
    • superset/migrations/versions/2020-01-08_01-17_e96dbf2cfef0_datasource_cluster_fk.py
    • superset/migrations/versions/2020-04-24_10-46_e557699a813e_add_tables_relation_to_row_level_.py
    • superset/migrations/versions/2022-04-01_14-38_a9422eeaae74_new_dataset_models_take_2.py
    • superset/migrations/versions/2024-01-17_13-09_96164e3017c6_tagged_object_unique_constraint.py
    • superset/models/helpers.py
    • superset/utils/core.py
    • tests/unit_tests/db_engine_specs/test_bigquery.py
    • tests/unit_tests/db_engine_specs/test_datastore.py
    • tests/unit_tests/db_engine_specs/test_mssql.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ 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 [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@hy144328
hy144328 force-pushed the refactor/sqlalchemy-migration-select-statements branch from fbc5308 to 3ba3ce7 Compare June 15, 2026 22:36
@hy144328

Copy link
Copy Markdown
Contributor Author

Just rebased the branch, but this is generally looking ready to approve to my eyes. Would love to have the bot comments addressed, but otherwise just waiting on a second opinion from @villebro @michael-s-molina @betodealmeida @dpgaspar

@rusackas I have addressed the bot comments, and included their suggestions in the most recent commits.
In particular, since the scope of this PR is focused on select() warnings ( see #40273 ), I originally did not pay a lot of attention to those warnings since they will be addressed by a subsequent PR eventually.

Otherwise, I rebased and re-ran all unit tests, successfully.
From my end, I think we are still good to go, and kick off the path to SQLAlchemy 2. :-)

@bito-code-review

bito-code-review Bot commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #f81737

Actionable Suggestions - 0
Filtered by Review Rules

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

  • superset/migrations/versions/2022-04-01_14-38_a9422eeaae74_new_dataset_models_take_2.py - 1
Review Details
  • Files reviewed - 15 · Commit Range: 8023023..3ba3ce7
    • pytest.ini
    • superset/commands/importers/v1/utils.py
    • superset/common/tags.py
    • superset/connectors/sqla/models.py
    • superset/db_engine_specs/base.py
    • superset/extensions/metadb.py
    • superset/migrations/versions/2020-01-08_01-17_e96dbf2cfef0_datasource_cluster_fk.py
    • superset/migrations/versions/2020-04-24_10-46_e557699a813e_add_tables_relation_to_row_level_.py
    • superset/migrations/versions/2022-04-01_14-38_a9422eeaae74_new_dataset_models_take_2.py
    • superset/migrations/versions/2024-01-17_13-09_96164e3017c6_tagged_object_unique_constraint.py
    • superset/models/helpers.py
    • superset/utils/core.py
    • tests/unit_tests/db_engine_specs/test_bigquery.py
    • tests/unit_tests/db_engine_specs/test_datastore.py
    • tests/unit_tests/db_engine_specs/test_mssql.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ 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 [email protected].

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.

Thanks for the work here @hy144328, and thanks for the review @betodealmeida.

LGTM2

@rusackas
rusackas merged commit 883b7a2 into apache:master Jun 18, 2026
59 checks passed
@hy144328
hy144328 deleted the refactor/sqlalchemy-migration-select-statements branch June 18, 2026 07:26
rusackas pushed a commit that referenced this pull request Jun 22, 2026
Forward-compatible groundwork for the SQLAlchemy 1.4 -> 2.0 bump. Every
change here is backward-compatible with the current SQLAlchemy 1.4.54 /
Flask-SQLAlchemy 2.5.1 baseline, so it does not regress anything while
shrinking the eventual version bump.

Removed-in-2.0 API fixes (these break on 2.0 but still work on 1.4):
- `sqlalchemy.orm.eagerload` (removed alias of `joinedload`) in the
  security manager.
- `sqlalchemy.sql.visitors.VisitableType` (removed) -> `sqlalchemy.types.TypeEngine`
  in dataset importer and mock_data type hints.
- `flask_sqlalchemy.BaseQuery` (removed in FSA 3.x, required by SA 2.0) ->
  import from `flask_sqlalchemy.query.Query` with a fallback to the FSA 2.x
  path, in the query/saved-query filters and the report command tests.
- `Engine.execute` / raw-string execution -> wrap startup health check in a
  `Connection` + `text()`, and the secrets re-encryptor in `text()` with a
  single bind dict and `row._mapping[...]` access.

Prospective Annotated Declarative prep (no-ops on 1.4, ease the 2.0 flip):
- `__allow_unmapped__` on the FAB declarative base so legacy 1.x annotations
  are tolerated during incremental migration.
- `Mapped[...]` return annotations on `created_by_fk`/`changed_by_fk` and
  `BaseDatasource.slices`.

The `select()` and `case()` syntax changes from the same effort already
landed via #40276 / #40275, so they are intentionally excluded here.

Co-Authored-By: Claude Fable 5 <[email protected]>
rusackas pushed a commit that referenced this pull request Jun 23, 2026
Forward-compatible groundwork for the SQLAlchemy 1.4 -> 2.0 bump. Every
change here is backward-compatible with the current SQLAlchemy 1.4.54 /
Flask-SQLAlchemy 2.5.1 baseline, so it does not regress anything while
shrinking the eventual version bump.

Removed-in-2.0 API fixes (these break on 2.0 but still work on 1.4):
- `sqlalchemy.orm.eagerload` (removed alias of `joinedload`) in the
  security manager.
- `sqlalchemy.sql.visitors.VisitableType` (removed) -> `sqlalchemy.types.TypeEngine`
  in dataset importer and mock_data type hints.
- `flask_sqlalchemy.BaseQuery` (removed in FSA 3.x, required by SA 2.0) ->
  import from `flask_sqlalchemy.query.Query` with a fallback to the FSA 2.x
  path, in the query/saved-query filters and the report command tests.
- `Engine.execute` / raw-string execution -> wrap startup health check in a
  `Connection` + `text()`, and the secrets re-encryptor in `text()` with a
  single bind dict and `row._mapping[...]` access.

Prospective Annotated Declarative prep (no-ops on 1.4, ease the 2.0 flip):
- `__allow_unmapped__` on the FAB declarative base so legacy 1.x annotations
  are tolerated during incremental migration.
- `Mapped[...]` return annotations on `created_by_fk`/`changed_by_fk` and
  `BaseDatasource.slices`.

The `select()` and `case()` syntax changes from the same effort already
landed via #40276 / #40275, so they are intentionally excluded here.

Co-Authored-By: Claude Fable 5 <[email protected]>
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:db-migration PRs that require a DB migration 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.

4 participants