You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to integrate the latest version of the library in my project, and i have faced the issue i can't find a solution for - i cannot make the cleanup work for usage mid-function.
Most of the time my usage of containers/providers is highly conventional and matches FastAPI+SQLAlchemy example. So here's some simplified examples. The main container and the database containers are declared this way:
I have a function with a long execution time, which makes several calls to the database and each of these calls needs to be its own session (cause i update database records and need to do that in real-time).
When i need to use the service in some kind of limited span inside of a function, i encounter a bug(?) where it does not trigger cleanup after the session was used. i have tried several approaches and none of them seem to work. Here is what i want to do:
asyncdeflong_function():
asyncwithMainContainer.db.transaction_serviceasservice:
awaitservice.funcion_a()
# session is commited and closed during cleanup# more logicasyncwithMainContainer.db.transaction_serviceasservice:
awaitservice.function_b()
# new session is commited and closed during cleanup
I have tried creating service context managed functions, somewhat like below, but they do not trigger cleanup
@asynccontextmanager@injectasyncdefget_tx_service_ctx(
tx_service: TxService=Closing[Provide[MainContainer.db.session_factory]]
) ->AsyncGenerator[TxService, None]:
# somewhy under contextmanager container provides a futureserv=awaittx_serviceyieldservprint(serv)
The print at the end is triggered, but the cleanup of a session doesn't seem to be. What should i do? Can i make some kind of a workaround for this? I can't seem to find an alternative way in the docs nor in the examples
The text was updated successfully, but these errors were encountered:
I am trying to integrate the latest version of the library in my project, and i have faced the issue i can't find a solution for - i cannot make the cleanup work for usage mid-function.
Most of the time my usage of containers/providers is highly conventional and matches FastAPI+SQLAlchemy example. So here's some simplified examples. The main container and the database containers are declared this way:
Meanwhile the usage mostly works like that:
HOWEVER.
I have a function with a long execution time, which makes several calls to the database and each of these calls needs to be its own session (cause i update database records and need to do that in real-time).
When i need to use the service in some kind of limited span inside of a function, i encounter a bug(?) where it does not trigger cleanup after the session was used. i have tried several approaches and none of them seem to work. Here is what i want to do:
I have tried creating service context managed functions, somewhat like below, but they do not trigger cleanup
The print at the end is triggered, but the cleanup of a session doesn't seem to be. What should i do? Can i make some kind of a workaround for this? I can't seem to find an alternative way in the docs nor in the examples
The text was updated successfully, but these errors were encountered: