Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Pydantic v1 'RabbitQueue' object has no attribute 'routing_key' #136

Closed
Llewe opened this issue Sep 13, 2023 · 2 comments · Fixed by #137 or airtai/faststream#629
Closed

Bug: Pydantic v1 'RabbitQueue' object has no attribute 'routing_key' #136

Llewe opened this issue Sep 13, 2023 · 2 comments · Fixed by #137 or airtai/faststream#629
Labels
bug Something isn't working

Comments

@Llewe
Copy link

Llewe commented Sep 13, 2023

Describe the bug
When using PydanticV1 (i used 1.10.12) the RabbitRouter feature doesn't work with the @router.handle decorator.

To Reproduce

  1. install pydantic 1.10.12
  2. run code
import asyncio
from propan.brokers.rabbit import RabbitExchange, RabbitQueue
from propan import PropanApp, RabbitBroker, RabbitRouter

broker = RabbitBroker()
router = RabbitRouter()


queue = RabbitQueue(
    name="job.single",
    routing_key="job.single",
    auto_delete=True,
)

exchange = RabbitExchange(name="test")


@router.handle(queue=queue, exchange=exchange)
async def handler():
    print("handler")


broker.include_router(router)
app = PropanApp(broker)

if __name__ == "__main__":
    print("starting")
    asyncio.run(app.run())

Environment
Running Propan 0.1.5.23 with CPython 3.11.5 on Linux

Additional context
I know v1 is outdated but for now i can't switch to v2 since a lib we use is currently v1 only.

** Error Log**
The error i get (i replaced the absolute paths)

Traceback (most recent call last):
  File "project_folder/.venv/lib/python3.11/site-packages/propan/cli/app.py", line 219, in run
    await self._stop(log_level)
  File "project_folder/.venv/lib/python3.11/site-packages/propan/cli/app.py", line 233, in _stop
    await self._stop_event.wait()
  File "project_folder/.venv/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 1621, in wait
    await self._event.wait()
  File "/usr/lib/python3.11/asyncio/locks.py", line 213, in wait
    await fut
asyncio.exceptions.CancelledError: Cancelled by cancel scope 7fc8dc79bed0

During handling of the above exception, another exception occurred:

  + Exception Group Traceback (most recent call last):
  |   File "project_folder/src/simple_demo.py", line 26, in <module>
  |     asyncio.run(app.run())
  |   File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
  |     return runner.run(main)
  |            ^^^^^^^^^^^^^^^^
  |   File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
  |     return self._loop.run_until_complete(task)
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |   File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
  |     return future.result()
  |            ^^^^^^^^^^^^^^^
  |   File "project_folder/.venv/lib/python3.11/site-packages/propan/cli/app.py", line 217, in run
  |     async with anyio.create_task_group() as tg:
  |   File "project_folder/.venv/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 664, in __aexit__
  |     raise BaseExceptionGroup(
  | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "project_folder/.venv/lib/python3.11/site-packages/propan/cli/app.py", line 228, in _start
    |     await self._startup()
    |   File "project_folder/.venv/lib/python3.11/site-packages/propan/cli/app.py", line 243, in _startup
    |     await self.broker.start()
    |   File "project_folder/.venv/lib/python3.11/site-packages/propan/brokers/rabbit/rabbit_broker.py", line 179, in start
    |     queue = await self._init_handler(handler)
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "project_folder/.venv/lib/python3.11/site-packages/propan/brokers/rabbit/rabbit_broker.py", line 264, in _init_handler
    |     routing_key=handler.queue.routing,
    |                 ^^^^^^^^^^^^^^^^^^^^^
    |   File "project_folder/.venv/lib/python3.11/site-packages/propan/brokers/rabbit/schemas.py", line 60, in routing
    |     return self.routing_key or self.name or None
    |            ^^^^^^^^^^^^^^^^
    | AttributeError: 'RabbitQueue' object has no attribute 'routing_key'
    +------------------------------------
@Llewe Llewe added the bug Something isn't working label Sep 13, 2023
@Lancetnik Lancetnik linked a pull request Sep 13, 2023 that will close this issue
12 tasks
Lancetnik added a commit that referenced this issue Sep 13, 2023
* fix (#136): remove pydantic.Field exclude

* fix: prefix RabbitExchange problems too
@Lancetnik
Copy link
Owner

@Llewe
Thanks for the bug reporting
Just update Propan to 0.1.5.24 version - your examples works fine on it

@Llewe
Copy link
Author

Llewe commented Sep 14, 2023

Perfect! Thanks for the quick fix and for this awesome project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants