Skip to content

Commit 2b7a1fd

Browse files
committed
Make transaction behaviour consistent between Sync and Async implementation
1 parent 2777a8c commit 2b7a1fd

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

sqlalchemy_bind_manager/_unit_of_work.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from contextlib import contextmanager, asynccontextmanager
22
from typing import Iterable, Type, Iterator, AsyncIterator
33

4+
from sqlalchemy.ext.asyncio import AsyncSession
5+
from sqlalchemy.orm import Session
6+
47
from sqlalchemy_bind_manager import SQLAlchemyRepository, SQLAlchemyAsyncRepository
58
from sqlalchemy_bind_manager._bind_manager import SQLAlchemyBind, SQLAlchemyAsyncBind
69
from sqlalchemy_bind_manager._transaction_handler import (
@@ -21,9 +24,9 @@ def __init__(
2124
setattr(self, r.__name__, r(session=self._transaction_handler.session))
2225

2326
@contextmanager
24-
def transaction(self, read_only: bool = False) -> Iterator[None]:
25-
with self._transaction_handler.get_session(read_only=read_only) as s:
26-
yield s
27+
def transaction(self, read_only: bool = False) -> Iterator[Session]:
28+
with self._transaction_handler.get_session(read_only=read_only) as _s:
29+
yield _s
2730

2831

2932
class AsyncUnitOfWork:
@@ -40,6 +43,6 @@ def __init__(
4043
setattr(self, r.__name__, r(session=self._transaction_handler.session))
4144

4245
@asynccontextmanager
43-
async def transaction(self, read_only: bool = False) -> AsyncIterator[None]:
44-
async with self._transaction_handler.get_session(read_only=read_only):
45-
yield None
46+
async def transaction(self, read_only: bool = False) -> AsyncIterator[AsyncSession]:
47+
async with self._transaction_handler.get_session(read_only=read_only) as _s:
48+
yield _s

0 commit comments

Comments
 (0)