mongkok / fastapi-debug-toolbar

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

Versions Bug & No SQL queries were recorded during this request. #16

Closed AndreasMietk closed 1 year ago

AndreasMietk commented 2 years ago

Hi, im getting this error on the Versions Tab

image

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) :(

image image

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
takashi-yoneya commented 2 years ago

If you want to display SQLAlchemy queries, you must register the DB-engine as shown in the example below.

app/core/database.py

    from sqlalchemy import create_engine
    from debug_toolbar.panels.sqlalchemy import SQLAlchemyPanel
    engine = create_engine(...)  # Please set your settings
    class SQLAlchemyPanel_(SQLAlchemyPanel):
        async def process_request(self, request: Request) -> Response:
            self.register(engine)
            try:
                return await super().process_request(request)
            finally:
                self.unregister(engine)

app/main.py

app = FastAPI(..., debug=True)

app.add_middleware(
     DebugToolbarMiddleware,
     panels=["core.database.SQLAlchemyPanel_"],
)

My repository below incorporates these. https://github.com/takashi-yoneya/fastapi-mybest-template/blob/master/app/core/database.py

mongkok commented 1 year ago

Thanks @AndreasMietk for sharing this, the issue is fixed, see #22 and v0.3.0.

BhuwanPandey commented 1 year ago

Thanks @AndreasMietk for sharing this, the issue is fixed, see #22 and v0.3.0.

I am facing the same problem as mention in title that is no sql were recorded during the calling the endpoint. I tried different method as mention but it didnot work. Seems like this issue hasnot been fixed.