Skip to content

Python db contracts are synchronous while the rest of the Python SDK is async (event-loop blocking) #23

Description

@ccisnedev

Problem

The Python core SDK is fully async/ASGI (Starlette + Uvicorn), e.g. UseCase.execute is declared async def:

  • code/py/modular_api/src/modular_api/core/usecase.py:200 -> async def execute(self) -> O

But the Python db contracts are synchronous (def, not async def):

  • code/py/modular_api_sqlserver/src/modular_api_sqlserver/db_client.py:212-249 -> DbSessionProvider.acquire/close, DbCommandExecutor.query/execute/scalar, DbTransactionRunner.run are all sync. Same in modular_api_postgres.

Why this is a defect, not an idiomatic choice

An async def execute() use case that calls a synchronous db repository performs blocking network I/O inside the asyncio event loop, degrading the concurrency of the whole ASGI server. TS and Dart contracts are already async (Promise/Future), so this is also a real parity gap specific to Python.

Fix

Make the Python db contracts async:

  • DbSessionProvider, DbCommandExecutor, DbTransactionRunner protocols -> async def.
  • DbTransactionContext / DbRepositoryContext helper methods -> async.
  • Update package tests to match.

Notes

  • Breaking in Python (signatures change). There are no Python consumers in production today (current consumers are TypeScript), so the cost of doing this now is ~0 and grows over time.
  • Dedicated iteration — must NOT be mixed with feature work (per EDD "no mezclar alcances"). Tracked separately from DbClient: typed parameters (DbParameter) and stored-procedure support across all db packages #22 (G2/G3 additive).
  • Decide whether it ships as a coordinated ecosystem bump (ADR-0002) and how it interacts with the contracts-only ADR-0004.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions