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 don't think we can reasonably support this without requiring to add some abstractions that make it rather useless as a feature. The issue here is that we cannot distinguish between a dependency that is meant to be used as a contextmanager, and a dependency that just happens to be a contextmanager.
E.g.
fromsqlalchemy.ormimportSessiondefprovide_session() ->Session:
session=get_session() # gets session from somewherereturnsessionapp=Litestar(depenencies={"session": provide_session})
this wouldn't work, because Session is a context manager, and Litestar would try to call its __enter__ and __exit__ methods, causing unintended side-effects.
We could solve this by providing some wrapper that indicates that this dependency provider should be treated as a context manager, but then again you can achieve the same thing with
Summary
We currently support generator based dependencies, but not context managers. For instance the following works:
But adding an context manager decorator like this:
produces
Basic Example
No response
Drawbacks and Impact
No response
Unresolved questions
No response
Note
While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.
Check out all issues funded or available for funding on our Polar.sh dashboard
The text was updated successfully, but these errors were encountered: