BeanieODM / beanie

Asynchronous Python ODM for MongoDB
http://beanie-odm.dev/
Apache License 2.0
1.99k stars 211 forks source link

Issues with initializing a View #715

Closed gsakkis closed 11 months ago

gsakkis commented 11 months ago

I run into two issues when passing a View model to init_beanie:

  1. The result of list_collection_names contains "system.views" instead of my view name. This means that the condition if self.recreate_views or cls._settings.name not in collection_names is always True and it always attempt to (re)create the view.

  2. I am getting an intermittent, non-deterministic exception from PyMongo: pymongo.errors.OperationFailure: Namespace ... is a view, not a collection. Apparently this happens in a thread so it doesn't stop the overall execution but it's still worrying. Full traceback:

    Future exception was never retrieved
    future: <Future finished exception=OperationFailure("Namespace [...] is a view, not a collection, full error: {'ok': 0.0, 'errmsg': 'Namespace [...] is a view, not a collection', 'code': 166, 'codeName': 'CommandNotSupportedOnView'}")>
    Traceback (most recent call last):
    File ".../lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
    File ".../lib/python3.10/site-packages/pymongo/collection.py", line 2173, in drop_indexes
    self.drop_index("*", session=session, **kwargs)
    File ".../lib/python3.10/site-packages/pymongo/_csot.py", line 108, in csot_wrapper
    return func(self, *args, **kwargs)
    File ".../lib/python3.10/site-packages/pymongo/collection.py", line 2235, in drop_index
    self._command(
    File ".../lib/python3.10/site-packages/pymongo/collection.py", line 310, in _command
    return conn.command(
    File ".../lib/python3.10/site-packages/pymongo/helpers.py", line 315, in inner
    return func(*args, **kwargs)
    File ".../lib/python3.10/site-packages/pymongo/pool.py", line 932, in command
    return command(
    File ".../lib/python3.10/site-packages/pymongo/network.py", line 191, in command
    helpers._check_command_response(
    File ".../lib/python3.10/site-packages/pymongo/helpers.py", line 223, in _check_command_response
    raise OperationFailure(errmsg, code, response, max_wire_version)
    pymongo.errors.OperationFailure: Namespace [...] is a view, not a collection, full error: {'ok': 0.0, 'errmsg': 'Namespace [...] is a view, not a collection', 'code': 166, 'codeName': 'CommandNotSupportedOnView'}
gsakkis commented 11 months ago

It turns out both issues were user (my) errors: