mongkok / fastapi-debug-toolbar Goto Github PK
View Code? Open in Web Editor NEWA debug toolbar for FastAPI.
Home Page: https://fastapi-debug-toolbar.domake.io
License: BSD 3-Clause "New" or "Revised" License
A debug toolbar for FastAPI.
Home Page: https://fastapi-debug-toolbar.domake.io
License: BSD 3-Clause "New" or "Revised" License
When trying to open http://localhost:XXXX/docs
:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 364, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "/usr/local/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 75, in __call__
return await self.app(scope, receive, send)
File "/usr/local/lib/python3.9/site-packages/fastapi/applications.py", line 212, in __call__
await super().__call__(scope, receive, send)
File "/usr/local/lib/python3.9/site-packages/starlette/applications.py", line 112, in __call__
await self.middleware_stack(scope, receive, send)
File "/usr/local/lib/python3.9/site-packages/starlette/middleware/errors.py", line 181, in __call__
raise exc
File "/usr/local/lib/python3.9/site-packages/starlette/middleware/errors.py", line 159, in __call__
await self.app(scope, receive, _send)
File "/usr/local/lib/python3.9/site-packages/starlette/middleware/base.py", line 64, in __call__
await response(scope, receive, send)
File "/usr/local/lib/python3.9/site-packages/starlette/responses.py", line 244, in __call__
await wrap(partial(self.listen_for_disconnect, receive))
File "/usr/local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 574, in __aexit__
raise exceptions[0]
File "/usr/local/lib/python3.9/site-packages/starlette/responses.py", line 240, in wrap
await func()
File "/usr/local/lib/python3.9/site-packages/starlette/responses.py", line 234, in stream_response
await send({"type": "http.response.body", "body": b"", "more_body": False})
File "/usr/local/lib/python3.9/site-packages/starlette/middleware/errors.py", line 156, in _send
await send(message)
File "/usr/local/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 468, in send
output = self.conn.send(event)
File "/usr/local/lib/python3.9/site-packages/h11/_connection.py", line 468, in send
data_list = self.send_with_data_passthrough(event)
File "/usr/local/lib/python3.9/site-packages/h11/_connection.py", line 501, in send_with_data_passthrough
writer(event, data_list.append)
File "/usr/local/lib/python3.9/site-packages/h11/_writers.py", line 60, in __call__
self.send_eom(event.headers, write)
File "/usr/local/lib/python3.9/site-packages/h11/_writers.py", line 83, in send_eom
raise LocalProtocolError("Too little data for declared Content-Length")
h11._util.LocalProtocolError: Too little data for declared Content-Length
On first iteration, body
equals the correct body from response (b'<HTML CONTENT>'
), on second iteration body
is empty (b''
). This empty body is use on the subsequent code, inserted on response, but line 97 never occurs.
app.add_middleware(
DebugToolbarMiddleware,
panels=["debug_toolbar.panels.sqlalchemy.SQLAlchemyPanel"],
)
when i add this middleware i got an ISE like fastapi.exceptions.HTTPException
This exception is coming from current user Dependency.
when comment the panels parameter, its working. no ISE occuring.
But need to track the sqlquery count. so can't comment it
app.add_middleware(
DebugToolbarMiddleware,
# panels=["debug_toolbar.panels.sqlalchemy.SQLAlchemyPanel"],
)
fastapi-debug-toolbar/debug_toolbar/panels/sql.py
Lines 120 to 121 in 3552b0b
Using UUID field raise an exception
*** TypeError: Object of type UUID is not JSON serializable
I suggest, adding UUID serialization, by cast to str
if isinstance(obj, UUID):
return str(obj)
Or allow setting encoder on json.dumps method
Here is the error stack information:
Traceback (most recent call last):
File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap
self.run()
File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/site-packages/uvicorn/_subprocess.py", line 76, in subprocess_started
target(sockets=sockets)
File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/site-packages/uvicorn/server.py", line 60, in run
return asyncio.run(self.serve(sockets=sockets))
File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/site-packages/uvicorn/server.py", line 67, in serve
config.load()
File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/site-packages/uvicorn/config.py", line 477, in load
self.loaded_app = import_from_string(self.app)
File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/site-packages/uvicorn/importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
File "xxx/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "./main.py", line 18, in <module>
app.add_middleware(
File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/site-packages/starlette/applications.py", line 169, in add_middleware
self.middleware_stack = self.build_middleware_stack()
File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/site-packages/fastapi/applications.py", line 195, in build_middleware_stack
app = cls(app=app, **options)
File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/site-packages/debug_toolbar/middleware.py", line 31, in __init__
self.settings = DebugToolbarSettings(**settings)
File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/site-packages/debug_toolbar/settings.py", line 139, in __init__
loaders = self.JINJA_LOADERS + [PackageLoader("debug_toolbar", "templates")]
File "/xxx/pypoetry/virtualenvs/py3.8/lib/python3.8/site-packages/jinja2/loaders.py", line 323, in __init__
raise ValueError(
ValueError: The 'debug_toolbar' package was not installed in a way that PackageLoader understands.
So what happened with this version v0.3.0?
Can some useful help information be provided for this error?
Thanks a lot!
OS: windows 10
python 3.8
fastapi 0.109.1
Project's toml file, it support python 3.8.
but type error occurred:
this error not showing 0.5 version.
app.add_middleware(
DebugToolbarMiddleware,
panels=["debug_toolbar.panels.sqlalchemy.SQLAlchemyPanel"],
)
this is stack trace.
from debug_toolbar.middleware import DebugToolbarMiddleware
File "C:\proj\venv\lib\site-packages\debug_toolbar\middleware.py", line 16, in <module>
from debug_toolbar.api import render_panel
File "C:\proj\venv\lib\site-packages\debug_toolbar\api.py", line 6, in <module>
from debug_toolbar.toolbar import DebugToolbar
File "C:\proj\venv\lib\site-packages\debug_toolbar\toolbar.py", line 12, in <module>
from debug_toolbar.settings import DebugToolbarSettings
File "C:\proj\venv\lib\site-packages\debug_toolbar\settings.py", line 12, in <module>
class DebugToolbarSettings(BaseSettings):
File "C:\proj\venv\lib\site-packages\pydantic\_internal\_model_construction.py", line 181, in __new__
set_model_fields(cls, bases, config_wrapper, types_namespace)
File "C:\proj\venv\lib\site-packages\pydantic\_internal\_model_construction.py", line 426, in set_model_fields
fields, class_vars = collect_model_fields(cls, bases, config_wrapper, types_namespace, typevars_map=typevars_map)
File "C:\proj\venv\lib\site-packages\pydantic\_internal\_fields.py", line 120, in collect_model_fields
type_hints = get_cls_type_hints_lenient(cls, types_namespace)
File "C:\proj\venv\lib\site-packages\pydantic\_internal\_typing_extra.py", line 212, in get_cls_type_hints_lenient
hints[name] = eval_type_lenient(value, globalns, localns)
File "C:\proj\venv\lib\site-packages\pydantic\_internal\_typing_extra.py", line 224, in eval_type_lenient
return typing._eval_type(value, globalns, localns) # type: ignore
File "C:\Users\rio\AppData\Local\Programs\Python\Python38\lib\typing.py", line 270, in _eval_type
return t._evaluate(globalns, localns)
File "C:\Users\rio\AppData\Local\Programs\Python\Python38\lib\typing.py", line 518, in _evaluate
eval(self.__forward_code__, globalns, localns),
File "<string>", line 1, in <module>
TypeError: 'type' object is not subscriptable```
I am not quite sure what to do about the error
RuntimeError: Failed to stop profiling. Make sure that you start/stop profiling on the same thread.
It happens regularly, but not for every request. It also affects different endpoints.
The endpoints use SQLAlchemy with the following config:
db_engine = create_engine(
f"mysql+mysqlconnector://{config.DB_USER}:{config.DB_PASSWORD}@{config.DB_HOST}:{config.DB_PORT}/{config.DB_NAME}",
connect_args={"connect_timeout": 10},
pool_recycle=3600,
pool_pre_ping=True,
pool_size=10,
max_overflow=40
)
For example:
@router.get("/get_list", status_code=200, response_model=list[SchemaOut],)
def get_list(
session: Session = Depends(create_session),
):
data = session.query(
[..]
).join(
[..]
).filter(
[..]
).order_by(
[..]
).all()
return data
There is only one uvicorn worker that is started with
pipenv run uvicorn app.api:app
Is it possible to disable profiling? It seems optional in the web ui.
I would also be thankful for help finding the source of the error.
I do not really know how to debug this.
Full stacktrace:
ERROR: Exception in ASGI application
+ Exception Group Traceback (most recent call last):
| File "[..].venv/lib/python3.11/site-packages/starlette/_utils.py", line 87, in collapse_excgroups
| yield
| File "[..].venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 190, in __call__
| async with anyio.create_task_group() as task_group:
| File "[..].venv/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 678, in __aexit__
| raise BaseExceptionGroup(
| ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "[..].venv/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 411, in run_asgi
| result = await app( # type: ignore[func-returns-value]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "[..].venv/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 69, in __call__
| return await self.app(scope, receive, send)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "[..].venv/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
| await super().__call__(scope, receive, send)
| File "[..].venv/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
| await self.middleware_stack(scope, receive, send)
| File "[..].venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
| raise exc
| File "[..].venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
| await self.app(scope, receive, _send)
| File "[..].venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
| with collapse_excgroups():
| File "[..].pyenv/versions/3.11.4/lib/python3.11/contextlib.py", line 155, in __exit__
| self.gen.throw(typ, value, traceback)
| File "[..].venv/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
| raise exc
| File "[..].venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 191, in __call__
| response = await self.dispatch_func(request, call_next)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "[..].venv/lib/python3.11/site-packages/debug_toolbar/middleware.py", line 75, in dispatch
| response = t.cast(StreamingResponse, await toolbar.process_request(request))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "[..].venv/lib/python3.11/site-packages/debug_toolbar/panels/__init__.py", line 79, in process_request
| return await self.call_next(request)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "[..].venv/lib/python3.11/site-packages/debug_toolbar/panels/timer.py", line 58, in process_request
| return await super().process_request(request)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "[..].venv/lib/python3.11/site-packages/debug_toolbar/panels/__init__.py", line 79, in process_request
| return await self.call_next(request)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "[..].venv/lib/python3.11/site-packages/debug_toolbar/panels/__init__.py", line 79, in process_request
| return await self.call_next(request)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "[..].venv/lib/python3.11/site-packages/debug_toolbar/panels/__init__.py", line 79, in process_request
| return await self.call_next(request)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| [Previous line repeated 2 more times]
| File "[..].venv/lib/python3.11/site-packages/debug_toolbar/panels/logging.py", line 96, in process_request
| return await super().process_request(request)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "[..].venv/lib/python3.11/site-packages/debug_toolbar/panels/__init__.py", line 79, in process_request
| return await self.call_next(request)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "[..].venv/lib/python3.11/site-packages/debug_toolbar/panels/profiling.py", line 28, in process_request
| await call(self.profiler.stop)
| File "[..].venv/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 2144, in run_sync_in_worker_thread
| return await future
| ^^^^^^^^^^^^
| File "[..].venv/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 851, in run
| result = context.run(func, *args)
| ^^^^^^^^^^^^^^^^^^^^^^^^
| File "[..].venv/lib/python3.11/site-packages/pyinstrument/profiler.py", line 151, in stop
| raise RuntimeError(
| RuntimeError: Failed to stop profiling. Make sure that you start/stop profiling on the same thread.
+------------------------------------
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "[..].venv/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 411, in run_asgi
result = await app( # type: ignore[func-returns-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[..].venv/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 69, in __call__
return await self.app(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[..].venv/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
await super().__call__(scope, receive, send)
File "[..].venv/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
await self.middleware_stack(scope, receive, send)
File "[..].venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
raise exc
File "[..].venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
await self.app(scope, receive, _send)
File "[..].venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
with collapse_excgroups():
File "[..].pyenv/versions/3.11.4/lib/python3.11/contextlib.py", line 155, in __exit__
self.gen.throw(typ, value, traceback)
File "[..].venv/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
raise exc
File "[..].venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 191, in __call__
response = await self.dispatch_func(request, call_next)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[..].venv/lib/python3.11/site-packages/debug_toolbar/middleware.py", line 75, in dispatch
response = t.cast(StreamingResponse, await toolbar.process_request(request))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[..].venv/lib/python3.11/site-packages/debug_toolbar/panels/__init__.py", line 79, in process_request
return await self.call_next(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[..].venv/lib/python3.11/site-packages/debug_toolbar/panels/timer.py", line 58, in process_request
return await super().process_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[..].venv/lib/python3.11/site-packages/debug_toolbar/panels/__init__.py", line 79, in process_request
return await self.call_next(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[..].venv/lib/python3.11/site-packages/debug_toolbar/panels/__init__.py", line 79, in process_request
return await self.call_next(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[..].venv/lib/python3.11/site-packages/debug_toolbar/panels/__init__.py", line 79, in process_request
return await self.call_next(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Previous line repeated 2 more times]
File "[..].venv/lib/python3.11/site-packages/debug_toolbar/panels/logging.py", line 96, in process_request
return await super().process_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[..].venv/lib/python3.11/site-packages/debug_toolbar/panels/__init__.py", line 79, in process_request
return await self.call_next(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[..].venv/lib/python3.11/site-packages/debug_toolbar/panels/profiling.py", line 28, in process_request
await call(self.profiler.stop)
File "[..].venv/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 2144, in run_sync_in_worker_thread
return await future
^^^^^^^^^^^^
File "[..].venv/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 851, in run
result = context.run(func, *args)
^^^^^^^^^^^^^^^^^^^^^^^^
File "[..].venv/lib/python3.11/site-packages/pyinstrument/profiler.py", line 151, in stop
raise RuntimeError(
RuntimeError: Failed to stop profiling. Make sure that you start/stop profiling on the same thread.
Used versions:
fastapi >=0.106 has breaking changes, was removed AsyncExitStack from concurrency
To Fix:
change import
from fastapi.concurrency import AsyncExitStack
to:
from contextlib import AsyncExitStack
Hi,
im getting this error on the Versions Tab
And i am not able to get any SQL query response. I am using the Depends() function on my routes,
Tried with sqllite and maria db with no success. The dependency injection setup is as the docs requsted.
The same results with starting via python3 form my machine or docker (python:3.10.3-alpine) :(
my requirements.txt
fastapi==0.78.0
uvicorn[standard]==0.18.2
gunicorn==20.1.0
uuid==1.30
python-multipart==0.0.5
weasyprint==55.0
SQLAlchemy==1.4.39
PyJWT==2.4.0
cairocffi==1.3.0
aiofiles==0.8.0
PyPDF2==2.4.1
bcrypt==3.2.2
greenlet==1.1.2
sentry-sdk==1.6.0
fastapi_msal==0.1.7
itsdangerous==2.1.2
fastapi-debug-toolbar==0.2.1
pydantic~=1.9.1
starlette~=0.19.1
flake8
alembic==1.8.0
PyMySQL~=1.0.2
Hi,
I try it in a very simple Fastapi apps alike:
from debug_toolbar.middleware import DebugToolbarMiddleware
from fastapi import FastAPI
app = FastAPI(debug=True)
app.add_middleware(DebugToolbarMiddleware)
@app.get("/")
async def root():
return {"message": "Hello World"}
start with :uvicorn main :app
and doesn't works , I don't see the toolbar
logs:
INFO: Application startup complete.
INFO: 127.0.0.1:61005 - "GET / HTTP/1.1" 200 OK
INFO: 127.0.0.1:61005 - "GET /docs HTTP/1.1" 200 OK
INFO: 127.0.0.1:61005 - "GET /_debug_toolbar/static/css/toolbar.css HTTP/1.1" 304 Not Modified
INFO: 127.0.0.1:50609 - "GET /_debug_toolbar/static/js/toolbar.js HTTP/1.1" 304 Not Modified
INFO: 127.0.0.1:61063 - "GET /_debug_toolbar/static/js/refresh.js HTTP/1.1" 304 Not Modified
INFO: 127.0.0.1:60063 - "GET /_debug_toolbar/static/img/icon-white.svg HTTP/1.1" 304 Not Modified
INFO: 127.0.0.1:61063 - "GET /_debug_toolbar/static/css/print.css HTTP/1.1" 304 Not Modified
INFO: 127.0.0.1:60063 - "GET /openapi.json HTTP/1.1" 200 OK
Hi, I was just trying to install in a fastapi app and i got this message from pydantic
File "/home/mariofix/proyectos/ferias-libres-data-fastapi/api.py", line 9, in <module>
from ferias_libres import create_app, __version__
File "/home/mariofix/proyectos/ferias-libres-data-fastapi/ferias_libres/__init__.py", line 2, in <module>
from .fastapi_app import create_app
File "/home/mariofix/proyectos/ferias-libres-data-fastapi/ferias_libres/fastapi_app.py", line 5, in <module>
from debug_toolbar.middleware import DebugToolbarMiddleware
File "/home/mariofix/.cache/pypoetry/virtualenvs/ferias-libres-data-fastapi-omql9Umt-py3.11/lib/python3.11/site-packages/debug_toolbar/middleware.py", line 16, in <module>
from debug_toolbar.api import render_panel
File "/home/mariofix/.cache/pypoetry/virtualenvs/ferias-libres-data-fastapi-omql9Umt-py3.11/lib/python3.11/site-packages/debug_toolbar/api.py", line 6, in <module>
from debug_toolbar.toolbar import DebugToolbar
File "/home/mariofix/.cache/pypoetry/virtualenvs/ferias-libres-data-fastapi-omql9Umt-py3.11/lib/python3.11/site-packages/debug_toolbar/toolbar.py", line 10, in <module>
from debug_toolbar.settings import DebugToolbarSettings
File "/home/mariofix/.cache/pypoetry/virtualenvs/ferias-libres-data-fastapi-omql9Umt-py3.11/lib/python3.11/site-packages/debug_toolbar/settings.py", line 5, in <module>
from pydantic import BaseSettings, Field, IPvAnyAddress, root_validator
File "/home/mariofix/.cache/pypoetry/virtualenvs/ferias-libres-data-fastapi-omql9Umt-py3.11/lib/python3.11/site-packages/pydantic/__init__.py", line 207, in __getattr__
return _getattr_migration(attr_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/mariofix/.cache/pypoetry/virtualenvs/ferias-libres-data-fastapi-omql9Umt-py3.11/lib/python3.11/site-packages/pydantic/_migration.py", line 288, in wrapper
raise PydanticImportError(
pydantic.errors.PydanticImportError: `BaseSettings` has been moved to the `pydantic-settings` package. See https://docs.pydantic.dev/2.0.3/migration/#basesettings-has-moved-to-pydantic-settings for more details.
For further information visit https://errors.pydantic.dev/2.0.3/u/import-error
My dependencies
[tool.poetry.dependencies]
python = "^3.11"
uvicorn = {extras = ["standard"], version = "^0.22.0"}
fastapi = {extras = ["all"], version = "^0.100.0"}
python-slugify = "^8.0.1"
python-dotenv = "^1.0.0"
pymysql = "^1.1.0"
python-multipart = "^0.0.6"
sentry-sdk = {extras = ["fastapi"], version = "^1.28.1"}
pydantic = "^2.0.3"
sqlalchemy-repr = "^0.1.0"
pydantic-settings = "^2.0.2"
typer = {version = "^0.9.0", extras = ["all"]}
[tool.poetry.group.dev.dependencies]
pytest = "^7.4.0"
coverage = "^7.2.7"
pre-commit = "^3.3.3"
fastapi-debug-toolbar = "^0.4.0"
show "No SQL queries were recorded during this request."
I've experienced collisions on the JSON.parse
function. When using the fastapi-debug-toolbar
and /docs
on fastapi
which uses openapi
module.
refresh.js
file redefines JSON.parse
functions, excluding the reviver parameter. This cause issues on the function on get_swagger_ui_oauth2_redirect_html()
function on file https://github.com/tiangolo/fastapi/blob/master/fastapi/openapi/docs.py.
JSON.parse
is used on L140:
qp = qp ? JSON.parse('{' + arr.join() + '}',
function (key, value) {
return key === "" ? value : decodeURIComponent(value)
}
) : {}
that uses the reviver function. The original implementation is not executed, but your overridden function, which does not include the reviver function which causes issues on encoded URI character not being properly decoded.
Greetings
from debug_toolbar.utils import render_stacktrace
ImportError: cannot import name 'render_stacktrace' from 'debug_toolbar.utils' (/Users/venv/lib/python3.9/site-packages/debug_toolbar/utils.py)
Having the following issue:
ORM: tortoise
DB: postgresql
python version: 3.9
fastapi 0.104.0
Is it possible to add SqlModel panel support for query monitoring
I tried to get ALLOWED_IPS to work and found that the test
remote_addr in settings.ALLOWED_IPS
in https://github.com/mongkok/fastapi-debug-toolbar/blob/main/debug_toolbar/middleware.py#L25
always returns False
because remote_addr
is of type str
and ALLOWED_IPS
is a list of type IPv4Address
.
Printing the variables in question returns for
print(f"{remote_addr} in {settings.ALLOWED_IPS}: {remote_addr in settings.ALLOWED_IPS}")
print(f"{type(remote_addr)} {type(settings.ALLOWED_IPS[0])}")
the results
127.0.0.1 in [IPv4Address('127.0.0.1'), IPv4Address('1.2.3.4')]: False
<class 'str'> <class 'ipaddress.IPv4Address'>
Thanks for this great project. It is really helpful and simplifies the migration from django to fastapi.
I use SQLAlchemyPanel and have a mysql table with a binary column described by:
filedata: Mapped[bytes] = mapped_column(LONGBLOB)
When updating this column with binary data, I receive the following error
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9d in position 15: invalid start byte
Traceback is
File "[..].venv/lib/python3.11/site-packages/debug_toolbar/panels/sqlalchemy.py", line 44, in after_execute
self.add_query(str(context.engine.url), query)
File "[..].venv/lib/python3.11/site-packages/debug_toolbar/panels/sql.py", line 110, in add_query
self._queries.append((alias, jsonable_encoder(query)))
^^^^^^^^^^^^^^^^^^^^^^^
File "[..].venv/lib/python3.11/site-packages/fastapi/encoders.py", line 289, in jsonable_encoder
encoded_value = jsonable_encoder(
^^^^^^^^^^^^^^^^^
File "[..].venv/lib/python3.11/site-packages/fastapi/encoders.py", line 303, in jsonable_encoder
jsonable_encoder(
File "[..].venv/lib/python3.11/site-packages/fastapi/encoders.py", line 289, in jsonable_encoder
encoded_value = jsonable_encoder(
^^^^^^^^^^^^^^^^^
File "[..].venv/lib/python3.11/site-packages/fastapi/encoders.py", line 318, in jsonable_encoder
return ENCODERS_BY_TYPE[type(obj)](obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[..].venv/lib/python3.11/site-packages/fastapi/encoders.py", line 59, in <lambda>
bytes: lambda o: o.decode(),
^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9d in position 15: invalid start byte
A simplified example for a fastapi endpoint is
@router.get("/test_binary/")
def test_binary(session: Session = Depends(create_session)):
import io
import xlsxwriter
xlb = io.BytesIO()
workbook = xlsxwriter.Workbook(xlb)
worksheet = workbook.add_worksheet("Test")
worksheet.name = 'Worksheet'
workbook.close()
export = session.query(BinaryTable).filter([..]).first()
export.filedata = xlb.getvalue()
session.commit()
It seems that the bytes parameter cannot be logged.
Used versions:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.