Skip to content

Upgrade SQLAlchemy v1 to v2 (Python 3.14 blocker)#3293

Open
MaxGhenis wants to merge 1 commit intomasterfrom
upgrade-sqlalchemy-v2
Open

Upgrade SQLAlchemy v1 to v2 (Python 3.14 blocker)#3293
MaxGhenis wants to merge 1 commit intomasterfrom
upgrade-sqlalchemy-v2

Conversation

@MaxGhenis
Copy link
Collaborator

Summary

  • Upgrade sqlalchemy>=1.4,<2 to sqlalchemy>=2,<3
  • SQLAlchemy v1 does not support Python 3.14, blocking full 3.14 compatibility
  • Migrates all v1 patterns to v2: connection-based execution, explicit commits, Row instead of LegacyRow

Ref: #2822 (comment)

Changes

  • setup.py: bump SQLAlchemy to v2
  • data.py: replace removed engine.execute() with connection-based exec_driver_sql() + _ResultProxy wrapper
  • *_service.py: LegacyRowRow
  • 10 new SQLAlchemy v2 compatibility tests

Test plan

  • All 443 tests pass locally (330 unit + 103 to_refactor + 10 new)
  • CI passes with org secrets

🤖 Generated with Claude Code

SQLAlchemy v1 does not support Python 3.14, making this upgrade a blocker.

Key changes:
- Update setup.py pin from sqlalchemy>=1.4,<2 to sqlalchemy>=2,<3
- Replace removed engine.execute() with connection-based execution
  using conn.exec_driver_sql() inside a connection context manager
- Add _ResultProxy wrapper to eagerly fetch results so they survive
  connection closure (maintains existing fetchone()/fetchall() API)
- Replace LegacyRow (removed in v2) with Row in type annotations
- Update test mocks that used spec=LegacyRow to use plain MagicMock()
  since Row in v2 has a different interface
- Add 10 dedicated SQLAlchemy v2 compatibility tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Feb 25, 2026

Codecov Report

❌ Patch coverage is 91.66667% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.29%. Comparing base (1e18234) to head (8cad222).
⚠️ Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
policyengine_api/data/data.py 89.28% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3293      +/-   ##
==========================================
+ Coverage   70.10%   72.29%   +2.19%     
==========================================
  Files          56       56              
  Lines        2398     2422      +24     
  Branches      419      422       +3     
==========================================
+ Hits         1681     1751      +70     
+ Misses        641      592      -49     
- Partials       76       79       +3     

☔ 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.

@MaxGhenis MaxGhenis requested a review from anth-volk February 25, 2026 20:42
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.

1 participant