Skip to content

Migration to SQLAlchemy 2.0 and Python 3.10+#326

Merged
TeddyCr merged 7 commits into
sqlalchemy-redshift:mainfrom
TeddyCr:SQA2-Migration
Mar 27, 2026
Merged

Migration to SQLAlchemy 2.0 and Python 3.10+#326
TeddyCr merged 7 commits into
sqlalchemy-redshift:mainfrom
TeddyCr:SQA2-Migration

Conversation

@TeddyCr

@TeddyCr TeddyCr commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Upgrade SQLAlchemy dependency from >=0.9.2 to >=2.0.0,<3
  • Set python_requires='>=3.10'
  • Remove legacy redshift_sqlalchemy compatibility package
  • Modernize codebase: convert .format() strings to f-strings, add encoding='utf-8' to open() calls, apply linting
  • Fix _get_column_info override to use _reflect_type() directly (parent method was removed in SQLAlchemy 2.0)
  • Update sa.select([...]) list syntax to positional args (sa.select(...))
  • Fix test fixture conftest.py where --dbdriver default was not applied, causing TypeError: 'NoneType' object is not iterable
  • Add psycopg2-binary to test dependencies
  • Update test utilities and models for SQLAlchemy 2.0 API changes

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the project to target SQLAlchemy 2.x and Python 3.10+, removing legacy compatibility shims and modernizing dialect/reflection code plus tests to match the SQLAlchemy 2.0 API surface.

Changes:

  • Upgrade runtime/test tooling to SQLAlchemy 2.0 and Python >=3.10; refresh tox/docs/lint dependencies.
  • Refactor the Redshift dialect reflection/DDL/command compilation logic for SQLAlchemy 2.0 (including multi-reflection behavior and type reflection).
  • Update and reformat the test suite to SQLAlchemy 2.0 query APIs and current Python style; remove the legacy redshift_sqlalchemy compatibility package.

Reviewed changes

Copilot reviewed 33 out of 34 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tox.ini Updates tox env matrix and pins newer test/lint/docs dependencies.
setup.py Sets python_requires>=3.10, upgrades SQLAlchemy requirement to 2.x, removes legacy package, adds extras.
setup.cfg Adds isort/flake8 config and attempts to add Black config.
requirements-docs.txt Updates Sphinx/numpydoc and doc build dependencies.
sqlalchemy_redshift/init.py Switches version detection to importlib.metadata and updates dialect registrations.
sqlalchemy_redshift/dialect.py Major SQLAlchemy 2.0 compatibility updates for reflection, types, DBAPI import, and compiler behavior.
sqlalchemy_redshift/ddl.py Modernizes DDL helpers/compilers and string formatting for 2.0-era SQLAlchemy.
sqlalchemy_redshift/commands.py Modernizes command construction/compilation and formatting; removes legacy compatibility branches.
redshift_sqlalchemy/init.py Removes the legacy compatibility module package.
docs/conf.py Reformats/modernizes Sphinx config (but retains old intersphinx mapping).
.gitignore Adds common local dev artifacts (.python-version, .vscode).
tests/conftest.py Fixes --dbdriver default handling and modernizes fixtures/style.
tests/rs_sqla_test_utils/utils.py Updates compilation helpers for SQLAlchemy 2.0; adds string passthrough in compile_query.
tests/rs_sqla_test_utils/models.py Migrates to declarative_base() and updates model/table args for 2.0 style.
tests/rs_sqla_test_utils/db.py Updates engine definition helper and driver-specific connect args.
tests/test_alembic_dialect.py Updates alembic dialect tests for new formatting/import ordering.
tests/test_alter_table.py Updates tests and formatting; keeps behavior assertions.
tests/test_column_loading.py Updates column reflection tests for 2.0 API and formatting.
tests/test_compiler.py Updates select() invocation to SQLAlchemy 2.0 positional args syntax.
tests/test_constraint_names.py Updates assertion/style and call formatting.
tests/test_copy_command.py Updates COPY command tests to 2.0 select() syntax and modern formatting.
tests/test_create_library.py Updates CREATE LIBRARY tests and modernizes string handling.
tests/test_ddl_compiler.py Modernizes DDL compiler tests (but introduces a Python 3-incompatible debug helper).
tests/test_default_ssl.py Switches cert path resolution to importlib.resources.
tests/test_delete_stmt.py Modernizes delete compilation tests to 2.0 select() style and formatting.
tests/test_dialect_types.py Updates type tests and reflection inspection for SQLAlchemy 2.0 APIs.
tests/test_dialects.py Removes legacy redshift_sqlalchemy-based assertions and keeps dialect inheritance checks.
tests/test_get_table_attributes.py Modernizes parameterization and imports; keeps DDL attribute assertions.
tests/test_materialized_views.py Updates MV tests to SQLAlchemy 2.0 select() patterns and selectable handling.
tests/test_reflection.py Updates reflection tests for autoload_with / unbound MetaData() usage.
tests/test_reflection_views.py Updates view reflection tests for SQLAlchemy 2.0 autoloading and formatting.
tests/test_relationkey_unquoted.py Refactors parametrization/style only.
tests/test_simple_query.py Updates string quoting/style only.
tests/test_unload_from_select.py Updates UNLOAD tests to SQLAlchemy 2.0 select() syntax and modern formatting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread setup.cfg
Comment thread sqlalchemy_redshift/dialect.py
Comment thread tests/test_ddl_compiler.py Outdated
Comment thread sqlalchemy_redshift/dialect.py
Comment thread docs/conf.py
Comment thread setup.cfg Outdated
@TeddyCr TeddyCr merged commit bf6fa88 into sqlalchemy-redshift:main Mar 27, 2026
@amotl amotl mentioned this pull request Apr 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants