Hello,
I am using the motor library in a simple aiohttp API backend and came across the following issue. When the aggregation that should return just one document was interrupted because web request was aborted, result of get_more (first i suppose) to the cancelled future. So an InvalidStateError exception is raised.
The code part looks like this:
def handler(request): pipeline = [{'$match': {...}}, {'$group': {'_id': 'k', 'v': {'$avg': '$smth'}}}] cursor = coll.aggregate(pipeline) data = [doc async for doc in cursor] return json_response(data)
Here is the traceback:
[2020-01-15 20:12:51,508] [ERROR] [asyncio] Exception in callback AgnosticLatentCommandCursor._on_started(<Future cancelled>, <Future finis...7f30909eb160>>) handle: <Handle AgnosticLatentCommandCursor._on_started(<Future cancelled>, <Future finis...7f30909eb160>>)> Traceback (most recent call last): File "/home/user/.pyenv/versions/3.7.2/lib/python3.7/asyncio/events.py", line 88, in _run self._context.run(self._callback, *self._args) File "/home/user/api/.venv/lib/python3.7/site-packages/motor/core.py", line 1542, in _on_started len(self.delegate._CommandCursor__data)) asyncio.base_futures.InvalidStateError: invalid state
- related to
-
MOTOR-467 AgnosticBaseCursor error when killing an aggregation query in process.
- Closed