Skip to content

Error in combined methods #1

@maliffi

Description

@maliffi

Hi,
first of all I'd like to thank you for having shared your fixes on this project that seems abandoned by its first author.
We are experiencing some issue using the mongo new combined methods (like find_and_update, find_and_delete, etc.)
The reason seems related to the fact that the single wrapper method async_decorator cannot work with these kind of methods because, inside, mongomock actually calls two methods (i.e. find_one and delete) and both requires an await but the decorator is applied only on the outer method.

I attach below the stacktrace trying to call a find_one_and_delete:

old = <coroutine object async_decorator.<locals>.wrapped at 0x10ef8f140>

    def _find_and_modify(self, query, projection=None, update=None,
                         upsert=False, sort=None,
                         return_document=ReturnDocument.BEFORE, session=None, **kwargs):
        if session:
            raise_not_implemented('session', 'Mongomock does not handle sessions yet')
        remove = kwargs.get('remove', False)
        if kwargs.get('new', False) and remove:
            # message from mongodb
            raise OperationFailure("remove and returnNew can't co-exist")
    
        if not (remove or update):
            raise ValueError('Must either update or remove')
    
        if remove and update:
            raise ValueError("Can't do both update and remove")
    
        old = self.find_one(query, projection=projection, sort=sort)
        if not old and not upsert:
            return
    
>       if old and '_id' in old:
E       TypeError: argument of type 'coroutine' is not iterable

venv/lib/python3.9/site-packages/mongomock/collection.py:1328: TypeError

any idea on how this could be resolved?

Thank you

Matteo

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions