classContainer(containers.DeclarativeContainer):
config=providers.Configuration()
# Define two resourcesdb_connection=providers.Resource(
db_connection,
db_url=config.db_url,
)
# The second resource depends on the first oneuser_session=providers.Resource(
user_session,
db=db_connection
)
Result:
File "src/dependency_injector/providers.pyx", line 168, in dependency_injector.providers.Provider.__call__
File "src/dependency_injector/providers.pyx", line 2970, in dependency_injector.providers.Resource._provide
AttributeError: '_asyncio.Future' object has no attribute '__anext__'
The error goes away if I remove async from the first resource, of from both of them.
Full source code with reproducible error, using version 4.10.0:
importasynciofromdependency_injectorimportcontainers, providersasyncdefdb_connection(db_url: str):
yield {'connection': 'ok', 'url': db_url}
asyncdefuser_session(db=None):
yield {'session': 'ok', 'db': db}
classContainer(containers.DeclarativeContainer):
config=providers.Configuration()
# Define two resources, one depending upon anotherdb_connection=providers.Resource(
db_connection,
db_url=config.db_url,
)
user_session=providers.Resource(
user_session,
db=db_connection
)
if__name__=='__main__':
# Init the containercontainer=Container(
config={'db_url': 'postgres://...'}
)
# Runasyncdefmain():
try:
# Get the resourceuser=awaitcontainer.user_session()
print('user', user)
finally:
awaitcontainer.shutdown_resources()
asyncio.run(main())
The text was updated successfully, but these errors were encountered:
Hi, thanks for a wonderful project :)
I just discovered that the following container:
Result:
The error goes away if I remove
async
from the first resource, of from both of them.Full source code with reproducible error, using version 4.10.0:
The text was updated successfully, but these errors were encountered: