Skip to content

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

Open
hy144328 wants to merge 5 commits into
apache:masterfrom
hy144328:refactor/sqlalchemy-migration-select-statements
Open

refactor: update SQLAlchemy select() syntax to 2.0#40276
hy144328 wants to merge 5 commits into
apache:masterfrom
hy144328:refactor/sqlalchemy-migration-select-statements

Conversation

@hy144328
Copy link
Copy Markdown

@hy144328 hy144328 commented May 19, 2026

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
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented May 19, 2026

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 evan@preset.io.

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
Copy link
Copy Markdown

netlify Bot commented May 19, 2026

Deploy Preview for superset-docs-preview ready!

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 on lines 51 to 55
statement = datasources.update().values(
cluster_id=sa.select([clusters.c.id])
cluster_id=sa.select(clusters.c.id)
.where(datasources.c.cluster_name == clusters.c.cluster_name)
.as_scalar()
)
Comment on lines 93 to 97
statement = datasources.update().values(
cluster_name=sa.select([clusters.c.cluster_name])
cluster_name=sa.select(clusters.c.cluster_name)
.where(datasources.c.cluster_id == clusters.c.id)
.as_scalar()
)
Comment thread pytest.ini
#addopts = -p no:warnings
asyncio_mode = auto

# `ignore` virtually reproduces to `-p no:warnings`.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

❌ Patch coverage is 29.41176% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.14%. Comparing base (8d2b655) to head (a81f704).
⚠️ Report is 90 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.16%   64.14%   -0.02%     
==========================================
  Files        2591     2591              
  Lines      138162   138223      +61     
  Branches    32048    32059      +11     
==========================================
+ Hits        88647    88669      +22     
- Misses      47986    48024      +38     
- Partials     1529     1530       +1     
Flag Coverage Δ
hive 39.44% <5.88%> (-0.02%) ⬇️
mysql 59.13% <23.52%> (-0.02%) ⬇️
postgres 59.21% <29.41%> (-0.03%) ⬇️
presto 41.13% <11.76%> (-0.02%) ⬇️
python 60.64% <29.41%> (-0.03%) ⬇️
sqlite 58.85% <23.52%> (-0.02%) ⬇️
unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

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.

2 participants