Skip to content

Conversation

@cofin
Copy link
Member

@cofin cofin commented Dec 14, 2025

Summary

  • Adds automatic query routing to read replicas for SELECT queries and to primary for writes
  • Provides context managers (primary_context, replica_context) for explicit routing control
  • Integrates with all framework extensions (Litestar, FastAPI, Starlette, Flask, Sanic)

Features

  • RoutingSession / RoutingAsyncSession with automatic get_bind() routing
  • RoutingConfig for configuring primary and replica connections
  • Round-robin and random replica selection strategies
  • Sticky-primary mode for write-then-read consistency
  • FOR UPDATE query detection for automatic primary routing

Test plan

  • 97 unit tests for routing components
  • 21 integration tests with real SQLite databases
  • All linting passes (make lint)

@codecov-commenter
Copy link

codecov-commenter commented Dec 15, 2025

Codecov Report

❌ Patch coverage is 99.26740% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.20%. Comparing base (947df81) to head (b179a91).

Files with missing lines Patch % Lines
advanced_alchemy/routing/session.py 97.29% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #635      +/-   ##
==========================================
+ Coverage   80.44%   81.20%   +0.76%     
==========================================
  Files          87       93       +6     
  Lines        6453     6726     +273     
  Branches      838      857      +19     
==========================================
+ Hits         5191     5462     +271     
- Misses        998      999       +1     
- Partials      264      265       +1     

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

cofin and others added 4 commits December 20, 2025 11:40
Implements automatic query routing to read replicas for SELECT queries
and to primary for writes, with context-based controls for forcing
primary or replica usage. Includes integration with all framework
extensions (Litestar, FastAPI, Starlette, Flask, Sanic).
Signed-off-by: Cody Fincher <[email protected]>
@cofin cofin force-pushed the feat/session-routing branch from 1594219 to 477730b Compare December 20, 2025 17:40
cofin and others added 2 commits December 20, 2025 19:07
- Removed `from __future__ import annotations` from multiple test files.
- Simplified type checking by directly importing necessary types.
- Updated assertions in tests to reflect changes in session class names from `RoutingSession` to `RoutingSyncSession`.
- Cleaned up comments in tests for clarity and conciseness.
- Ensured consistency in the use of mock engines and session creation across various test cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants