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

Flask debug toolbar doesnt show queries(shows unavailable) #7

Closed
ev-agelos opened this issue Oct 17, 2015 · 2 comments
Closed

Flask debug toolbar doesnt show queries(shows unavailable) #7

ev-agelos opened this issue Oct 17, 2015 · 2 comments

Comments

@ev-agelos
Copy link

As i am trying to make the "transition" from Flask-SQLAlchemy to your fork i found this problem where the debug toolbar doesnt show information about the queries, it just tells me that i have to install Flask-SQLAlachemy.

I saw a commit about supporting the toolbar in your fork but im not expert to debug what is wrong cause maybe im missing something.

# __init__.py
from flask import Flask
from sqlalchemy_wrapper import SQLAlchemy
from flask.ext.bcrypt import Bcrypt

app = Flask(__name__, instance_relative_config=True, static_url_path='')
bcrypt = Bcrypt(app)

app.config.from_pyfile('development.py')

db = SQLAlchemy(app.config['SQLALCHEMY_DATABASE_URI'], app=app)
# run.py
from flask_debugtoolbar import DebugToolbarExtension
toolbar = DebugToolbarExtension()
toolbar.init_app(app)
@ev-agelos ev-agelos changed the title Flask debug toolbar doesnt show queries Flask debug toolbar doesnt show queries(shows unavailable) Oct 17, 2015
@ghost
Copy link

ghost commented Oct 19, 2015

I'm sorry, this should be on the documentation.

In order to see the queries on the Flask debug toolbar, you must activate first the query recording using the argument record_queries:

db = SQLAlchemy(SQLALCHEMY_URI, app=app, record_queries=True)

(In Flask-SQLAlchemy this is done automatically if DEBUG is True... I'll probably do something similar soon)
Here is a functional (but boring) example:

"""
    pip install flask, sqlalchemy_wrapper, flask_debugtoolbar
"""
from flask import Flask
from sqlalchemy_wrapper import SQLAlchemy

app = Flask(__name__)
app.config['DEBUG'] = True
app.config['SECRET_KEY'] = 'loremipsumsitamet'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False

db = SQLAlchemy(
    app.config['SQLALCHEMY_DATABASE_URI'],
    record_queries=app.config['DEBUG'],
    app=app
)


class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Unicode)


@app.route("/")
def hello():
    db.query(User).all()
    return "<html><body>Hello World!</body></html>"

db.create_all()
db.add(User(name=u'Test'))
db.commit()

if __name__ == "__main__":

    if app.config['DEBUG']:
        import flask_debugtoolbar
        flask_debugtoolbar.DebugToolbarExtension(app)
    app.run()

@ghost ghost closed this as completed Oct 19, 2015
@ghost
Copy link

ghost commented Oct 19, 2015

BTW, although SQLAlchemy-Wrapper is kind-of framework-independent this integration only works with Flask and Flask-DebugToolbar :(

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant