mongkok / fastapi-debug-toolbar

A debug toolbar for FastAPI.
https://fastapi-debug-toolbar.domake.io
BSD 3-Clause "New" or "Revised" License
140 stars 14 forks source link

Remove arg name on call self.router.url_path_for() #33

Closed michael555444 closed 1 year ago

michael555444 commented 1 year ago

Fix call self.router.url_path_for() with name= argument on last fastapi version

michael555444 commented 1 year ago

Trace with using on last fastapi version (0.95.1) and python version 3.10

TRACE:    127.0.0.1:44602 - HTTP connection made
TRACE:    127.0.0.1:44602 - ASGI [3] Started scope={'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.3'}, 'http_version': '1.1', 'server': ('127.0.0.1', 6060), 'client': ('127.0.0.1', 44602), 'scheme': 'http', 'method': 'GET', 'root_path': '', 'path': '/favicon.ico', 'raw_path': b'/favicon.ico', 'query_string': b'', 'headers': '<...>', 'state': {}}
TRACE:    127.0.0.1:44602 - ASGI [3] Raised exception
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/path/to/project/venv/lib64/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 428, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/path/to/project/venv/lib64/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
  File "/path/to/project/venv/lib64/python3.10/site-packages/uvicorn/middleware/message_logger.py", line 86, in __call__
    raise exc from None
  File "/path/to/project/venv/lib64/python3.10/site-packages/uvicorn/middleware/message_logger.py", line 82, in __call__
    await self.app(scope, inner_receive, inner_send)
  File "/path/to/project/venv/lib64/python3.10/site-packages/fastapi/applications.py", line 276, in __call__
    await super().__call__(scope, receive, send)
  File "/path/to/project/venv/lib64/python3.10/site-packages/starlette/applications.py", line 121, in __call__
    self.middleware_stack = self.build_middleware_stack()
  File "/path/to/project/venv/lib64/python3.10/site-packages/fastapi/applications.py", line 201, in build_middleware_stack
    app = cls(app=app, **options)
  File "/path/to/project/venv/lib64/python3.10/site-packages/debug_toolbar/middleware.py", line 39, in __init__
    self.router.url_path_for(name="debug_toolbar.render_panel")
TypeError: Router.url_path_for() missing 1 required positional argument: '_Router__name'
INFO:     127.0.0.1:44602 - "GET /favicon.ico HTTP/1.1" 500 Internal Server Error
TRACE:    127.0.0.1:44602 - HTTP connection lost

image

Without name= calling image