aio-pika icon indicating copy to clipboard operation
aio-pika copied to clipboard

[6.7.1] TypeError('This message has "no_ack" flag.') raised from QueueIterator

Open HMaker opened this issue 3 years ago • 1 comments

I have the following coroutine function that consumes a queue using QueueIterator

async def _consume_queue(self, queue: aio_pika.Queue):
    async with queue.iterator(no_ack=True) as messages:
        try:
            async for msg in messages:
                pass # process message
        except asyncio.CancelledError:
            pass

but on cancellation it raises

File "example.py", line 483, in _consume_queue
    async for msg in messages:
  File ".../.venv/lib/python3.8/site-packages/aio_pika/queue.py", line 444, in __anext__
    await self.close()
  File ".../.venv/lib/python3.8/site-packages/aio_pika/tools.py", line 67, in awaiter
    return await future
  File ".../.venv/lib/python3.8/site-packages/aio_pika/queue.py", line 402, in close
    await msg.reject(requeue=True)
  File ".../.venv/lib/python3.8/site-packages/aio_pika/message.py", line 604, in reject
    raise TypeError('This message has "no_ack" flag.')
TypeError: This message has "no_ack" flag.

looks like a regression of #226

HMaker avatar Jul 06 '21 16:07 HMaker

I catch CancelledError to allow QueueIterator exit cleanly, see #358

HMaker avatar Jul 06 '21 16:07 HMaker