Open entropymatters opened 3 months ago
Hi! Thank you for the report. I'll pick it up during the next bug fixing session
That would be nice. This is basically the same problem that I reported some time ago but unfortunately it was closed. see Issue: #706
I can confirm that this only is a typing issue. Passing the motor.motor_asyncio.AsyncIOMotorClientSession
to the session
parameter works fine and the transaction is acutally used. I worked around the typing issue with # type: ignore
async with await db.client.start_session() as session:
async with session.start_transaction():
await mydocument.insert(session=session) # type: ignore
Describe the bug A comment in #536 gives an example of using database sessions and transactions with
beanie
. However, when one wants to factor out the session into a separate function and annotates it, it does not properly type check usingmypy
anymore. Interestingly, this is not the case for allDocument
methods, despitebeanie
annotatingsession
aspymongo.client_session.ClientSession
everywhere.I'd be glad to create a PR if the issue is really only to replace
pymongo.client_session.ClientSession
withmotor.motor_asyncio.AsyncIOMotorClientSession
, and would have a look in any other hints you can give for a fix.Note that just casting the session to a
pymongo
ClientSession
does not work since itsstart_session
method is no coroutine.To Reproduce
Current behavior
mypy
shows an error forfind()
(but not forinsert()
):Expected behavior Code type checks using
mypy
Additional context none