python-dependency-injector
python-dependency-injector copied to clipboard
Injecting an async resource into an async generator provides future instead of resource
First of all, thanks a lot for this library - it's really great work you are doing here!
We are relying on this library for a FastAPI project and we noticed that when we try to inject an async resource into an async generator, somehow the injected resource is still wrapped in a future.
We would expect the following minimal example to run without exception, but what we see is
AssertionError: resource is of type <class '_asyncio.Future'>
Of course we can easily work around that by doing another await
to get the actual resource, but it would of course be great if this could be fixed.
import asyncio
from dependency_injector import containers, providers
from dependency_injector.wiring import Provide, inject
class Resource:
pass
async def async_resource():
yield Resource()
class Container(containers.DeclarativeContainer):
resource = providers.Resource(async_resource)
@inject
async def async_generator(resource = Provide[Container.resource]):
yield resource
async def main():
container = Container()
container.wire([__name__])
await container.init_resources()
generator = async_generator()
resource = await anext(generator)
assert isinstance(resource, Resource), f"resource is of type {type(resource)}"
asyncio.run(main())
the same problem
Same issue.
What is the maintenance status of this lib? @rmk135
This issue seems to be important to be open for so long
+1 here. Hitting it as well.