reagento / dishka

Cute DI framework with agreeable API and everything you need
https://dishka.readthedocs.io
Apache License 2.0
428 stars 48 forks source link

AnyOf["SomeObject", "AnotherObject"] don't work #290

Closed Maclovi closed 2 weeks ago

Maclovi commented 1 month ago

I tried to specify types via strings but it gives an error. MRE:

@provide(scope=Scope.REQUEST)
async def new_async_session(
    self, session_factory: async_sessionmaker[AsyncSession]
) -> AsyncIterator[AnyOf["AsyncSession", "UoWProtocol"]]:
    async with session_factory() as session:
        yield session

Error: dishka.exceptions.GraphMissingFactoryError: Cannot find factory for (<class 'sqlalchemy.ext.asyncio.session.AsyncSession'>, component=''). It is missing or has invalid scope.

Tishka17 commented 1 month ago

Though it cannot be probably fixed, we should at least detect this and raise an error with a recommendation to replace with "AnyOf[AsyncSession, UoWProtocol]"