Closed ltieman closed 4 months ago
@roman-right we did figure out a workaround by overwriting the get_motor_collection method thusly:
@classmethod
def get_motor_collection(cls) -> AsyncIOMotorCollection:
item = super().get_motor_collection()
if item is None:
from libraries.mongo.mongodb import mongo_singleton
from motor.motor_asyncio import AsyncIOMotorCollection
cls.set_database(mongo_singleton.client.db)
name = cls.get_collection_name()
if not name:
name = cls.__name__
cls.set_collection(AsyncIOMotorCollection(
database=mongo_singleton.client.db,
name=name,
))
return cls.get_motor_collection()
return item
We are concerned about the overall impact of this, but it does seem to be working as of now. Any thoughts on why this could be happening?
This issue is stale because it has been open 30 days with no activity.
This issue was closed because it has been stalled for 14 days with no activity.
@ltieman I am now also using your workaround, the get_motor_collection overwrite to tackle my issue. In a multi-tenant Flask context, I have to call init_beanie on every Flask request to switch the tenant database, which leads to get_motor_collection to sporadically return None because of timing issues as described here.
Did you face any issues in the meanwhile with that workaround?
@roman-right is there any update on a fix within Beanie/Bunnet for that issue?
Describe the bug We are getting back None from get_motor_collection() but only sporadically when we we are under moderate volume.
This is our singleton for init_beanie
and this is our stacktrace:
Expected behavior We expect this to be able to fetch the links that are coming off of this Document, yet it can not because it is getting back a None. We do not have this behavior happening unless it is under load. When running tests, or under calls that are one at a time, it works. This seems similar to #440 though in our case, it works unless it is under a moderate load (10-20 calls) and only happens sporatically.