Skip to content

Commit b0fa9dc

Browse files
authored
Make sure async session is still open when we call .all(). (#55)
1 parent f2e55b3 commit b0fa9dc

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

RELEASE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Release type: patch
2+
3+
Make sure async session is still open when we call .all()

src/strawberry_sqlalchemy_mapper/loader.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ def __init__(
4545
"One of bind or async_bind_factory must be set for loader to function properly."
4646
)
4747

48-
async def _scalars(self, *args, **kwargs):
48+
async def _scalars_all(self, *args, **kwargs):
4949
if self._async_bind_factory:
5050
async with self._async_bind_factory() as bind:
51-
return await bind.scalars(*args, **kwargs)
51+
return (await bind.scalars(*args, **kwargs)).all()
5252
else:
5353
assert self._bind is not None
54-
return self._bind.scalars(*args, **kwargs)
54+
return self._bind.scalars(*args, **kwargs).all()
5555

5656
def loader_for(self, relationship: RelationshipProperty) -> DataLoader:
5757
"""
@@ -70,7 +70,7 @@ async def load_fn(keys: List[Tuple]) -> List[Any]:
7070
)
7171
if relationship.order_by:
7272
query = query.order_by(*relationship.order_by)
73-
rows = (await self._scalars(query)).all()
73+
rows = await self._scalars_all(query)
7474

7575
def group_by_remote_key(row: Any) -> Tuple:
7676
return tuple(

0 commit comments

Comments
 (0)