Skip to content

feat: full SQLAlchemy 2.0 support with 1.4 backward compat#36

Open
nwoolmer wants to merge 1 commit intomainfrom
phase1/sa2-full-support
Open

feat: full SQLAlchemy 2.0 support with 1.4 backward compat#36
nwoolmer wants to merge 1 commit intomainfrom
phase1/sa2-full-support

Conversation

@nwoolmer
Copy link
Contributor

@nwoolmer nwoolmer commented Mar 4, 2026

Summary

SQLAlchemy 2.0 compatibility while maintaining backward compat with SA 1.4. Bumps version to 1.2.0.

Dialect (dialect.py)

Inspector (inspector.py)

  • Engine.execute() is removed in SA 2.0 — all self.bind.execute() calls now go through a _get_connection() helper that opens a connection from the engine when needed, with proper cleanup

Packaging (pyproject.toml)

  • Declare runtime dependencies: SQLAlchemy>=1.4, psycopg2-binary>=2.9, packaging
  • Remove SQLAlchemy<2 cap from test dependencies
  • Add Python 3.12/3.13 classifiers
  • Add ruff ignores for new test file

Docker (Dockerfile, Makefile)

  • Debian Buster is EOL (repos 404) — update to python:3.13-slim-bookworm
  • Collapse RUN layers, remove stale SQLALCHEMY_SILENCE_UBER_WARNING
  • pip install . now picks up declared runtime deps

Tests (test_sa2_compat.py)

  • import_dbapi() returns the module
  • dbapi() still works (backward compat)
  • create_engine / create_superset_engine produce no deprecation warnings
  • SA_V2 flag matches installed SA version

Backward compatibility

On SA 1.4 (as used by Superset 4.x/5.x which pins sqlalchemy>=1.4, <2), every code path produces identical behavior to the original:

  • SA_V2 = Falsefuture= and implicit_returning= are passed as before
  • import_dbapi() exists but SA 1.4 calls dbapi() — both work
  • Inspector's _get_connection() calls Engine.connect() which works on both SA versions

Test plan

  • 28/28 tests pass on SQLAlchemy 2.0.48 + Python 3.13
  • ruff check clean
  • Docker image builds successfully
  • Verify tests pass on SQLAlchemy 1.4.x (CI)

Closes #9, closes #31
Refs #35

🤖 Generated with Claude Code

@nwoolmer nwoolmer force-pushed the phase1/sa2-full-support branch 3 times, most recently from aa2ba71 to 52ba319 Compare March 4, 2026 16:19
- Add import_dbapi() classmethod alongside dbapi() (fixes #9, #31)
- Version-conditional create_engine params (future/implicit_returning
  only passed on SA <2.0)
- Fix inspector to use connection-based execution (Engine.execute()
  removed in SA 2.0)
- Declare runtime dependencies in pyproject.toml
- Remove SQLAlchemy <2 cap from test dependencies
- Add Python 3.12/3.13 classifiers, bump version to 1.2.0
- Update Dockerfile from EOL buster to bookworm, Python 3.13
- Add SA 2.0 compatibility test suite

Closes #9, closes #31
Refs #35

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

SQLAlchemy SADeprecationWarning SADeprecationWarning - Implement an import_dbapi()

1 participant