pallets-eco / pallets-eco/flask-debugtoolbar
sql_select/sql_explain not working with Flask-SQLAlchemy 3 & SQLAlchemy 2
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 978
- Forks
- 151
- PR merge metrics
- No merged PRs in 30d
Description
sql_select() (panels/sqlalchemy.py) seems not tested in https://github.com/pallets-eco/flask-debugtoolbar/pull/186/. The updates introduce some API changes that affect how sql_select() operates:
get_engine()requires an initialized (init_app()ed)SQLAlchemyinstance.- The
Engineobject no longer has anexecute()method directly; instead, obtaining a connection is required for execution. - The
execute()method does not support positional parameters anymore.
To address these issues, I made some local modifications. Here are the specific changes:
142c142,143
< engine = SQLAlchemy().get_engine(current_app)
---
> sqlalchemy = current_app.extensions["sqlalchemy"]
> engine = sqlalchemy.get_engine()
150c151,152
< result = engine.execute(statement, params)
---
> with engine.connect() as connection:
> result = connection.exec_driver_sql(statement, tuple(params[0]))
Given that I'm uncertain about the repercussions these changes might have on backward compatibility with Flask-SQLAlchemy 2.x versions, and due to time constraints on my end, I'm hesitant to submit a pull request myself. However, it would be great if someone could validate and extend these adjustments to ensure compatibility across both Flask-SQLAlchemy 2.x and 3.x versions.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in panels/sqlalchemy.py at sql_select() and sql_explain(), then compare the Flask-SQLAlchemy 2.x and 3.x APIs described in the issue. Validate the engine initialization and connection execution changes across both versions. Done means both toolbar actions work without breaking either supported API.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, python, sqlalchemy
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100