-
-
Notifications
You must be signed in to change notification settings - Fork 108
Open
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers
Description
Summary
In sync method no context managers are used. Session lifecycle is managed by the caller.
class SQLASyncPersistence(SyncPersistenceProtocol[T]):
def __init__(self, session: Session) -> None:
"""Sync persistence handler for SQLAFactory."""
self.session = session
def save(self, data: T) -> T:
self.session.add(data)
self.session.commit()
return dataWhile in async method the session is closed on exit.
class SQLAASyncPersistence(AsyncPersistenceProtocol[T]):
def __init__(self, session: AsyncSession) -> None:
"""Async persistence handler for SQLAFactory."""
self.session = session
async def save(self, data: T) -> T:
async with self.session as session:
session.add(data)
await session.commit()
await session.refresh(data)
return dataI think it's better to make it consistent, so that the caller manages the session lifecycle.
Basic Example
No response
Drawbacks and Impact
async with session: closes the session, which may conflict with the caller’s lifecycle management.
Unresolved questions
No response
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers