michaelkryukov / mongomock_motor

Library for mocking AsyncIOMotorClient built on top of mongomock.
MIT License
102 stars 24 forks source link

Is start_session working/supported? #35

Closed jotradovec closed 1 year ago

jotradovec commented 1 year ago

When I tried to use start_session with MongoMockMotor it seemed to me, that it is not working. Was it fail in my code or it is not supported yet? Expected working code example:

async with await client.start_session() as s:
        doc = {'_id': ObjectId(), 'x': 1}
        await collection.insert_one(doc, session=s)

start_session on Motor docs: https://motor.readthedocs.io/en/stable/api-asyncio/asyncio_motor_client.html

michaelkryukov commented 1 year ago

This library uses mongomock, so here can find all the missing implementation features.

And yes, session options is not supported at this moment. Your code raises nice error NotImplementedError: Mongomock does not support sessions yet.

jotradovec commented 1 year ago

@michaelkryukov Thank you for the reply. But it seems to me that the code uses session without additional options. So the exception should pop up only, when I use options, right? Because coroutine async start_session(causal_consistency: Optional[bool] = None, default_transaction_options: Optional[pymongo.client_session.TransactionOptions] = None. So by default the options are None.

michaelkryukov commented 1 year ago

As I said, error message is pretty unambiguous (https://github.com/mongomock/mongomock/blob/ca41f27161c50d83d5ef8c899623084dd6f09a1d/mongomock/mongo_client.py#L180)

jotradovec commented 1 year ago

Yes, I see. :D You were right. And it looks like they are not going to support any time soon, because there are no new commits in the last 10 months.