mosquito / aio-pika

AMQP 0.9 client designed for asyncio and humans.
https://aio-pika.readthedocs.org/
Apache License 2.0
1.21k stars 187 forks source link

Documentation for RPC.create() has examples that are incorrect. #638

Open fake-name opened 1 month ago

fake-name commented 1 month ago

From the documentation of RPC.create():

rpc = await RPC.create(channel, host_exceptions=True)

However, trying that:

Traceback (most recent call last):
  File "/media/Scripts/book_cat/rabbit/rpc_llama.py", line 341, in <module>
    run()
  File "/media/Scripts/book_cat/rabbit/rpc_llama.py", line 337, in run
    asyncio.run(instance.run_rpc())
  File "/home/durr/miniconda3/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/home/durr/miniconda3/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/durr/miniconda3/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/media/Scripts/book_cat/rabbit/rpc_llama.py", line 324, in run_rpc
    rpc = await RPC.create(channel, host_exceptions=True)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/durr/miniconda3/lib/python3.12/site-packages/aio_pika/patterns/rpc.py", line 217, in create
    await rpc.initialize(**kwargs)
  File "/home/durr/miniconda3/lib/python3.12/site-packages/aio_pika/patterns/rpc.py", line 174, in initialize
    self.result_queue = await self.channel.declare_queue(
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: RobustChannel.declare_queue() got an unexpected keyword argument 'host_exceptions'

So....., host_exceptions is only valid when passed to RPC.__init__(), which create() does not use.

I dunno who wrote the examples in the docs, but they pretty obviously didn't try any of them.

fake-name commented 1 month ago

For the moment, I believe you can manually do rpc.host_exceptions = True to work around the issue.