Giter VIP home page Giter VIP logo

flask-debugtoolbar's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flask-debugtoolbar's Issues

Include the version number within the library

It would be nice to know which version of the toolbar is currently installed, exactly as in Flask..

Just include the __version__ = '0.8.0' in the __init__.py for the stable releases and use something like __version__ = '0.9.0-dev'for the master branch!

It would be also good idea to include that number inside the VersionDebugPanel so you will know which version of the toolbar is currently running.

SQLAlchemy 0 queries even for Flask-SQLAlchemy

Anyone else experiencing this?
Meanwhile I'll stick to SQLALCHEMY_ECHO = True, too bad, the toolbar is looking good and all other panels are working but I'm only interested in the queries.

Turn off logging after turn on debug toolbar

After

DebugToolbarExtension(app)
app.run(debug=True)

I can't see standart werkzeug HTTP log in console:

127.0.0.1 - - [19/Aug/2012 11:57:57] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [19/Aug/2012 11:57:57] "GET /static/styles/dropdown/dropdown.css HTTP/1.1" 304 -
127.0.0.1 - - [19/Aug/2012 11:57:57] "GET /static/styles/dropdown/default.advanced.css HTTP/1.1" 304 -
127.0.0.1 - - [19/Aug/2012 11:57:57] "GET /static/styles/layout.css HTTP/1.1" 304 -

Without DebugToolbarExtension(app) everything ok.

Buf when I run server, like this:

from werkzeug.serving import run_simple
DebugToolbarExtension(app)
run_simple('localhost', 5000, app)

everything fine.

Redirects incorrectly handled with subfolders.

There appears to be a problem with how the flask-debugtoolbar follows redirects, when the redirect goes into a subdirectory. For example, with the flask system I wrote to run the site for my webcomic:

I click the link http://localhost:5000/content/main/latest and it takes me to the redirect debug page as expected. Clicking the link to follow the redirect's destination should be http://localhost:5000/content/main/51 but it instead takes me to http://localhost:5000/content/main/content/main/52

I'll repeat those links one after another with the domain and port number chopped off, to better illustrate the difference:

Right Link: /content/main/51
Wrong Link: /content/main/content/main/51

With the wrong link, the /content/main subdirectory path is doubled, which in turn leads to a 404.

Use SQLAlchemy panel with plain SQLAlchemy

Now I can manage all my SQL queries only when I use Flask-SQLAlchemy.

Would be great, if I can see all my SQL queries when I use plain SQLAlchemy http://flask.pocoo.org/docs/patterns/sqlalchemy/#declarative.

Maybe something like this:

from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker

from flask_debugtoolbar import DebugToolbarExtension

engine = create_engine('sqlite:////tmp/test.db', convert_unicode=True)
db_session = scoped_session(sessionmaker(autocommit=False,
                                         autoflush=False,
                                         bind=engine))
toolbar = DebugToolbarExtension(app, db_session=db_session)

it seems I have to render something like render_template

my program just provide api, which will return jsonify() format, so is there any way that could add flask-debugtoolbar 's profiler tool without change the current api, as that's a lot of work.

do something in the @app.after_request will help? if so, How to ?
thanks

Python 3.3 "startswith" TypeError

Hi, I'm trying to enable the Toolbar for a Flask app running on Python 3.3, and I get this:

File "[...]/python3.3/site-packages/flask_debugtoolbar/templates/base.html", line 50, in
{{ panel.content()|safe }}
File "[...]/python3.3/site-packages/flask_debugtoolbar/panels/sqlalchemy.py", line 98, in content
'signed_query': dump_query(query.statement, query.parameters),
File "[...]/python3.3/site-packages/flask_debugtoolbar/panels/sqlalchemy.py", line 25, in dump_query
if not params or not statement.lower().strip().startswith('select'):
TypeError: startswith first arg must be bytes or a tuple of bytes, not str

Hoping to see a fix soon!

Convert tab indents to spaces

Some of the templates and JavaScript still uses tabs for indentation. It should all be updated to consistent spaces for indentation.

Raw Sqlalchemy

Hello!

I use Sqlalchemy without flask-sqlalchemy and canot see sql-queries.

Memory allocation panel

It would be nice to have a panel to profile memory usage like Dozer

Like the existing profiler panel, this should be disabled by default.

Support debugging SQL with datetime parameters

The SQL panel doesn't support debugging queries with datetime values as parameters. It currently uses JSON encoding to serialize the parameters, and datetime values are not supported in JSON. Should translate the datetime values to allow for JSON encoding.

SQLAlchemy panel not working

I've read the docs but I can't find any place that mentions how to enable SQLAlchemy panel. It's visible, but always shows 0 queries and is unclickable as in attached screenshot.
Please advise or point to some how-to as it's bugging me for some time,
fdt

Error for endpoints

Hi!
If I try to define a route by specify an endpoint to allow every method it fails like a champ. Here the full traceback:

Traceback (most recent call last):
  File "/Users/garito/TimeFounder/App/0.3/env/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/garito/TimeFounder/App/0.3/env/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/Users/garito/TimeFounder/App/0.3/env/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/garito/TimeFounder/App/0.3/env/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/garito/TimeFounder/App/0.3/env/lib/python2.7/site-packages/flask/app.py", line 1479, in full_dispatch_request
    response = self.process_response(response)
  File "/Users/garito/TimeFounder/App/0.3/env/lib/python2.7/site-packages/flask/app.py", line 1691, in process_response
    response = handler(response)
  File "/Users/garito/TimeFounder/App/0.3/env/lib/python2.7/site-packages/flask_debugtoolbar/__init__.py", line 223, in process_response
    toolbar_html = toolbar.render_toolbar()
  File "/Users/garito/TimeFounder/App/0.3/env/lib/python2.7/site-packages/flask_debugtoolbar/toolbar.py", line 46, in render_toolbar
    return template.render(**context)
  File "/Users/garito/TimeFounder/App/0.3/env/lib/python2.7/site-packages/jinja2/environment.py", line 969, in render
    return self.environment.handle_exception(exc_info, True)
  File "/Users/garito/TimeFounder/App/0.3/env/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/garito/TimeFounder/App/0.3/env/lib/python2.7/site-packages/flask_debugtoolbar/templates/base.html", line 50, in top-level template code
    {{ panel.content()|safe }}
  File "/Users/garito/TimeFounder/App/0.3/env/lib/python2.7/site-packages/flask_debugtoolbar/panels/route_list.py", line 33, in content
    'routes': self.routes,
  File "/Users/garito/TimeFounder/App/0.3/env/lib/python2.7/site-packages/flask_debugtoolbar/panels/__init__.py", line 30, in render
    return template.render(**context)
  File "/Users/garito/TimeFounder/App/0.3/env/lib/python2.7/site-packages/jinja2/environment.py", line 969, in render
    return self.environment.handle_exception(exc_info, True)
  File "/Users/garito/TimeFounder/App/0.3/env/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/garito/TimeFounder/App/0.3/env/lib/python2.7/site-packages/flask_debugtoolbar/templates/panels/route_list.html", line 17, in top-level template code
    <td>{{ route.methods|sort|join(', ') }}</td>
  File "/Users/garito/TimeFounder/App/0.3/env/lib/python2.7/site-packages/jinja2/filters.py", line 265, in do_sort
    return sorted(value, key=sort_func, reverse=reverse)
TypeError: 'NoneType' object is not iterable

Could someone point me how to solve this?

Thanks

UnicodeDecodeError

UnicodeDecodeError
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd1 in position 40: ordinal not in range(128)

Traceback (most recent call last)
File "/home/livarava/.env/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/home/livarava/.env/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/livarava/.env/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/home/livarava/.env/lib/python2.7/site-packages/flask/app.py", line 1479, in full_dispatch_request
response = self.process_response(response)
File "/home/livarava/.env/lib/python2.7/site-packages/flask/app.py", line 1691, in process_response
response = handler(response)
File "/home/livarava/.env/lib/python2.7/site-packages/flask_debugtoolbar/init.py", line 196, in process_response
toolbar_html = self.debug_toolbars[real_request].render_toolbar()
File "/home/livarava/.env/lib/python2.7/site-packages/flask_debugtoolbar/toolbar.py", line 45, in render_toolbar
return template.render(**context)
File "/home/livarava/.env/lib/python2.7/site-packages/jinja2/environment.py", line 969, in render
return self.environment.handle_exception(exc_info, True)
File "/home/livarava/.env/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/livarava/.env/lib/python2.7/site-packages/flask_debugtoolbar/templates/base.html", line 50, in top-level template code
{{ panel.content()|safe }}
File "/home/livarava/.env/lib/python2.7/site-packages/flask_debugtoolbar_lineprofilerpanel/panels.py", line 126, in content
'stats': processed_line_stats
File "/home/livarava/.env/lib/python2.7/site-packages/flask_debugtoolbar/panels/init.py", line 28, in render
return template.render(**context)
File "/home/livarava/.env/lib/python2.7/site-packages/jinja2/environment.py", line 969, in render
return self.environment.handle_exception(exc_info, True)
File "/home/livarava/.env/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/livarava/.env/lib/python2.7/site-packages/flask_debugtoolbar_lineprofilerpanel/templates/content.html", line 72, in top-level template code

{{ line }}
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd1 in position 40: ordinal not in range(128)

More example details

Not mentioned in the example shown are two things. One is why you save to a toolbar variable that is never used. (Presumably this is to prevent garbage collection in which case a comment to that effect would be helpful.)

The second is that the template being rendered requires a <head> section. The simplest template shown in http://flask.pocoo.org/docs/quickstart/ (search for "Here is an example template") omits html/head/body and as a result the toolbar doesn't show up.

Group repeated SQL queries

When the same SQL query is repeated multiple times within the same request, it would be useful to group the results.

For example, querying multiple records of the same type might be executed as the same SELECT statement repeated with different id parameters.

These could be grouped to show the total number of executions and aggregate times in order to make it easier to compare the distinct queries against each other. The groups could be expanded to show details for each occurrence.

Flask Debug Toolbar Does Not Check For A Compressed Response

If you have an extension like Flask Compress compressing the contents of your responses with gzip before it's sent back to the user, flask debug toolbar will throw an error because it assumes the response is UTF-8 HTML.

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/usr/local/lib/python2.7/site-packages/flask_restful/__init__.py", line 270, in error_router
    return original_handler(e)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1479, in full_dispatch_request
    response = self.process_response(response)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1691, in process_response
    response = handler(response)
  File "/usr/local/lib/python2.7/site-packages/flask_debugtoolbar/__init__.py", line 202, in process_response
    response_html = response.data.decode(response.charset)
  File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x8b in position 1: invalid start byte

Add option to enable the toolbar to display on JSON responses?

I am debugging a Flask app that serves up JSON for an API endpoint.

I'm viewing the JSON in the browser, and it'd be convenient to display the toolbar as well.

My understanding of content types is a little hazy... is it possible to add an option to display the toolbar alongside this JSON? Like perhaps a config setting that lets me turn on the toolbar for all responses, not just with <! doctype html>?

Can't move ProfilerDebugPanel above RequestVarsDebugPanel

If you reorder DEBUG_TB_PANELS so ProfilerDebugPanel comes before RequestVarsDebugPanel, you'll get an obscure error: AttributeError: 'functools.partial' object has no attribute '__module__'

This is OK:

DEBUG_TB_PANELS = [
    'flask_debugtoolbar.panels.request_vars.RequestVarsDebugPanel',
    'flask_debugtoolbar.panels.profiler.ProfilerDebugPanel',
]

This is not:

DEBUG_TB_PANELS = [
    'flask_debugtoolbar.panels.profiler.ProfilerDebugPanel',
    'flask_debugtoolbar.panels.request_vars.RequestVarsDebugPanel',
]

Screen Shot 2013-03-08 at 7 41 37 PM

Exception thrown when session key has multiple values

Commit a48efe8 (the fix for issue #9) breaks if you have multiple values in your session for a given key.

Inside request_vars.html, at line 61:

{{ show_map(session) }}

session in this case looks like this for me:

[('somevalue', (u'20bca7ecb', u'9d74f339e8)), ('email', u'[email protected]')]

that results in:

return string.encode('string_escape')

throwing:

AttributeError: 'tuple' object has no attribute 'encode'

Toolbar does not show when no body tag is present

Omitting the body tag is a valid practice in HTML and when not using any body tag the toolbar simply does not show.

The toolbar should at least log something to tell the developer why it is currently not showing up or better just be injected somewhere else when the body tag is missing.

More friendly installation docs

I suggest expanding readme a little, so that devs don't need to to open the source :)

Installation snippet won't work, as app.debug should be enabled prior toolbar initialization, not after.
Plus, The Flask-DebugToolbar requires the 'SECRET_KEY' config.

Escape HTML in .flDebugSql

"<" and ">" occuring in SQL should be escaped when output on the page in the .flDebugSql elements so as to create valid HTML.

Debug toolbar inline script isn't compatible with Content Security Policy

I noticed the following inline script in flask_debugtoolbar/templates/base.html isn't compatible with a common content security policy (CSP) rule that obviates XSS attacks by preventing the execution of inline scripts:

<script type="text/javascript">var DEBUG_TOOLBAR_STATIC_PATH = '{{ static_path }}'</script>

(One might say that CSP should be disabled on debug builds anyways, which is a fair point, but there's also an argument for dev/prod parity, especially when it's not that hard to achieve.)

A simple fix is to have this static path be defined in a data attribute that is subsequently pulled out of the DOM by one of the non-inline scripts.

In the meantime, if the default static_path of /_debug_toolbar/static/ is used, a hash-source of 'sha256-zWl5GfUhAzM8qz2mveQVnvu/VPnCS6QL7Niu6uLmoWU=' can be used to permit the inline script.

Support plain sql alchemy

Would be nice to get support for plain SQL Alchemy instead of requiring Flask-SQLAlchemy. Interest?

pip install fails on windows 7

When doing "pip install flask-debutoolbar" on windows 7 I get:

ValueError: path 'flaskext/debugtoolbar/templates/' cannot end with '/'

The issue seems to be in the MANIFEST.in. When I removed the trailing slash so that the file changes from:

recursive-include flask_debugtoolbar/templates/ *.html
recursive-include flask_debugtoolbar/static/ *

to:

recursive-include flask_debugtoolbar/templates *.html
recursive-include flask_debugtoolbar/static *

it installs correctly.

From the disutils docs it seems to me that the correct syntax is without a trailing slash, but I have little experience with disutils so I cant be sure. I have tried installing without the trailing slash on windows 7 and on ubuntu without any issues so it seems to be safe.

Error when sqlalchemy query has non-ascii characters

Happens because in the panel from sqlalchemy.py, the template is being rendered with the query as str type instead of unicode, and according to jinja2's documentation:

Unicode

Jinja2 is using Unicode internally which means that you have to pass Unicode objects to the render function or bytestrings that only consist of ASCII characters. Additionally newlines are normalized to one end of line sequence which is per default UNIX style (\n).

Python 2.x supports two ways of representing string objects. One is the str type and the other is the unicode type, both of which extend a type called basestring. Unfortunately the default is str which should not be used to store text based information unless only ASCII characters are used. With Python 2.6 it is possible to make unicode the default on a per module level and with Python 3 it will be the default.

Source:

for query in queries:
    data.append({
        'duration': query.duration,
        'sql': format_sql(query.statement, query.parameters),
        'signed_query': dump_query(query.statement, query.parameters),
        'context_long': query.context,
        'context': format_fname(query.context)
    })
return self.render('panels/sqlalchemy.html', { 'queries': data})

Should be:

for query in queries:
    data.append({
        'duration': query.duration,
        'sql': unicode(format_sql(query.statement, query.parameters), 'utf-8'),
        'signed_query': dump_query(query.statement, query.parameters),
        'context_long': query.context,
        'context': format_fname(query.context)
    })
return self.render('panels/sqlalchemy.html', { 'queries': data})

UnicodeDecodeError in Request Vars panel

Traceback (most recent call last):
  File "/Users/janne/Documents/Development/monitori/lib/python2.7/site-packages/flask/app.py", line 1518, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/janne/Documents/Development/monitori/monitori/middleware.py", line 17, in __call__
    return self.app(environ, start_response)
  File "/Users/janne/Documents/Development/monitori/lib/python2.7/site-packages/flask/app.py", line 1506, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/Users/janne/Documents/Development/monitori/lib/python2.7/site-packages/flask/app.py", line 1504, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/janne/Documents/Development/monitori/lib/python2.7/site-packages/flask/app.py", line 1266, in full_dispatch_request
    response = self.process_response(response)
  File "/Users/janne/Documents/Development/monitori/lib/python2.7/site-packages/flask/app.py", line 1414, in process_response
    response = handler(response)
  File "/Users/janne/Documents/Development/monitori/lib/python2.7/site-packages/flask_debugtoolbar/__init__.py", line 153, in process_response
    toolbar_html = self.debug_toolbars[real_request].render_toolbar()
  File "/Users/janne/Documents/Development/monitori/lib/python2.7/site-packages/flask_debugtoolbar/toolbar.py", line 71, in render_toolbar
    return template.render(**context)
  File "/Users/janne/Documents/Development/monitori/lib/python2.7/site-packages/jinja2/environment.py", line 894, in render
    return self.environment.handle_exception(exc_info, True)
  File "/Users/janne/Documents/Development/monitori/lib/python2.7/site-packages/flask_debugtoolbar/templates/base.html", line 47, in top-level template code
    {{ panel.content()|safe }}
  File "/Users/janne/Documents/Development/monitori/lib/python2.7/site-packages/flask_debugtoolbar/panels/request_vars.py", line 46, in content
    return self.render('panels/request_vars.html', context)
  File "/Users/janne/Documents/Development/monitori/lib/python2.7/site-packages/flask_debugtoolbar/panels/__init__.py", line 28, in render
    return template.render(**context)
  File "/Users/janne/Documents/Development/monitori/lib/python2.7/site-packages/jinja2/environment.py", line 894, in render
    return self.environment.handle_exception(exc_info, True)
  File "/Users/janne/Documents/Development/monitori/lib/python2.7/site-packages/flask_debugtoolbar/templates/panels/request_vars.html", line 71, in top-level template code
    <td>{{ value|escape }}</td>
  File "/Users/janne/Documents/Development/monitori/lib/python2.7/site-packages/jinja2/_markupsafe/_native.py", line 21, in escape
    return Markup(unicode(s)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf6 in position 1: ordinal not in range(128)

The value of s here is 'n\xf6R\x8dJ\xd4\x03fA] w\xdf{\x85\x03'

Don't support view decorators with parameters

def limit_post_request(allowed_in_24h):
"""
Limit Post Request in 24hour, like register and login
Using Flask-Cache
"""
def limit_post_request_decorator(func):
@wraps(func)
def func_wrapper(_args, *_kwargs):
"""should use incr(), but Flask-Cache don't support"""
tried = cache.get("IP:"+request.remote_addr)
if tried and tried > allowed_in_24h:
abort(403) # forbidden
else:
cache.set("IP:"+request.remote_addr, (tried or 0)+1, timeout=10)
return func(_args, *_kwargs)
return func_wrapper
return limit_post_request

def limit_post_request_decorator(func):
@wraps(func)
def func_wrapper(_args, *_kwargs):
"""should use incr(), but Flask-Cache don't support"""
tried = cache.get("IP:"+request.remote_addr)
if tried and tried > 2:
abort(403) # forbidden
else:
cache.set("IP:"+request.remote_addr, (tried or 0)+1, timeout=10)
return func(_args, *_kwargs)
return func_wrapper

@limit_post_request_decorator works well.
@limit_post_request(20) doesn't work:
Traceback (most recent call last):
File "C:\Users\j\Desktop\zhuigengxin_gae\lib\flask\app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "C:\Users\j\Desktop\zhuigengxin_gae\lib\flask\app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\j\Desktop\zhuigengxin_gae\lib\flask\app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\j\Desktop\zhuigengxin_gae\lib\flask\app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\j\Desktop\zhuigengxin_gae\lib\flask\app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\j\Desktop\zhuigengxin_gae\lib\flask\app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\j\Desktop\zhuigengxin_gae\lib\flask_debugtoolbar__init__.py", line 124, in dispatch_request
return view_func(*_req.view_args)
File "C:\Python27\lib\cProfile.py", line 149, in runcall
return func(_args, **kw)
TypeError: limit_post_request() takes exactly 1 argument (0 given)

Invalid unicode handling

When logging sql statements with sqlalchemy panel the following exception is thrown:

Traceback (most recent call last):
File "C:\Python27\lib\site-packages\flask\app.py", line 1518, in call
return self.wsgi_app(environ, start_response)
File "C:\Python27\lib\site-packages\flask\app.py", line 1506, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "C:\Python27\lib\site-packages\flask\app.py", line 1504, in wsgi_app
response = self.full_dispatch_request()
File "C:\Python27\lib\site-packages\flask\app.py", line 1266, in full_dispatch_request
response = self.process_response(response)
File "C:\Python27\lib\site-packages\flask\app.py", line 1414, in process_response
response = handler(response)
File "C:\Python27\lib\site-packages\flask_debugtoolbar__init__.py", line 171, in process_response
toolbar_html = self.debug_toolbars[real_request].render_toolbar()
File "C:\Python27\lib\site-packages\flask_debugtoolbar\toolbar.py", line 74, in render_toolbar
return template.render(**context)
File "C:\Python27\lib\site-packages\jinja2\environment.py", line 894, in render
return self.environment.handle_exception(exc_info, True)
File "C:\Python27\lib\site-packages\flask_debugtoolbar\templates\base.html", line 48, in top-level template code
{{ panel.content()|safe }}
File "C:\Python27\lib\site-packages\flask_debugtoolbar\panels\sqlalchemy.py", line 79, in content
query.statement + _params).hexdigest()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb2 in position 0: ordinal not in range(128)

As far as I understand, the panel concatenates application SECRET_KEY and query statement and params. My secret key is a byte string which contains some non-ascii characters like "'\xb2q\xf6\x8c\xcd\xd0\x023...". I had generated it with the following method which has been described in Flask quickstart docs:

import os
os.urandom(24)
'\xfd{H\xe5<\x95\xf9\xe3\x96.5\xd1\x01O<!\xd5\xa2\xa0\x9fR"\xa1\xa8'

http://flask.pocoo.org/docs/quickstart/

Windows Path prefix error

Windows users not all will probably have an error like this:

if not prefix.endswith(os.path.sep):
AttributeError: 'NoneType' object has no attribute 'endswith'

This is because of the path beign lower case on value and Capital/Default case on sys.path return.

A simply:

new_prefix = os.path.commonprefix([path.lower(), value]) - L41

would fix it, to ensure that value is always lowercased too I added on L19 the following

value = value.lower()

any changes or impact?

Python 3 compatibility

Recent updates to Flask and related components have included support for Python 3, and it would be great to be able to use Flask-DebugToolbar in projects running on Python 3. As it stands now, Flask-DebugToolbar must be disabled in such projects in order to run them without errors.

Are there plans to support Python 3 in the near future?

JavaScript error when using HTML5 boilerplate

The toolbar's CSS file isn't injected into the template when using the HTML5 boilerplate <html> element:

<!doctype html>
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->
<!--[if IE 7]>    <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]>    <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->

I would submit a pull request but I can't seem to find where this is being done.

memory leak over time

I'm still gathering data, but it appears as though recent flask-debugtoolbar versions cause a memory leak. After I upgraded to Flask and Werkzeug 0.8 I also had to update flask-debugtoolbar from baecf85 to current master (45ce65c), I've been noticing memory usage growing on every request made against the server.

I've disabled my custom panels and the ones from MongoEngine but left TimerDebugPanel, HeaderDebugPanel, RequestVarsDebugPanel, TemplateDebugPanel, LoggingPanel and ProfilerDebugPanel enabled.

Here is the output from heapy for a run with the debug panel disabled with DEBUG_TB_ENABLED=False. The first set is the total number of objects by type. The second set is the types of the objects that refer to the ones in the front. If you are familiar with heapy, the former is heap() and the latter is heap().byrcsL

Partition of a set of 202 objects. Total size = 40656 bytes.
 Index  Count   %     Size   % Cumulative  % Kind (class / dict of class)
     0     11   5     9224  23      9224  23 dict (no owner)
     1     16   8     8456  21     17680  43 types.FrameType
     2     59  29     5128  13     22808  56 str
     3     30  15     3728   9     26536  65 unicode
     4     16   8     1600   4     28136  69 list
     5      1   0     1048   3     29184  72 dict of flask.ctx.RequestContext
     6      1   0     1048   3     30232  74 dict of flask.wrappers.Request
     7      1   0     1048   3     31280  77 dict of flask.wrappers.Response
     8      1   0     1048   3     32328  80 dict of mimetools.Message
     9      1   0     1048   3     33376  82 dict of werkzeug.routing.MapAdapter
<35 more rows. Type e.g. '_.more' to view.>

Partition of a set of 202 objects. Total size = 40656 bytes.
 Index  Count   %     Size   % Cumulative  % Referrers by Kind (class / dict of class)
     0     22  11     7912  19      7912  19 types.FrameType
     1     67  33     7736  19     15648  38 dict (no owner)
     2      1   0     3352   8     19000  47 __builtin__.cell, dict of flask.wrappers.Request, dict
                                             of werkzeug.datastructures.EnvironHeaders,
                                             types.FrameType
     3     17   8     3136   8     22136  54 list
     4      6   3     1472   4     23608  58 dict of mimetools.Message
     5      2   1     1120   3     24728  61 dict of 0x7fca19073b90
     6      1   0     1048   3     25776  63 flask.ctx.RequestContext
     7      1   0     1048   3     26824  66 flask.wrappers.Request
     8      1   0     1048   3     27872  69 flask.wrappers.Response
     9      1   0     1048   3     28920  71 mimetools.Message
<41 more rows. Type e.g. '_.more' to view.>

A run with the debug toolbar enabled:

Partition of a set of 538 objects. Total size = 81920 bytes.
 Index  Count   %     Size   % Cumulative  % Kind (class / dict of class)
     0     35   7    20552  25     20552  25 dict (no owner)
     1    135  25    11128  14     31680  39 str
     2    122  23    10472  13     42152  51 tuple
     3     16   3     8208  10     50360  61 types.FrameType
     4     34   6     4064   5     54424  66 unicode
     5     31   6     4024   5     58448  71 list
     6     46   9     1104   1     59552  73 int
     7      1   0     1048   1     60600  74 dict of blinker._saferef.BoundMethodWeakref
     8      1   0     1048   1     61648  75 dict of flask.ctx.RequestContext
     9      1   0     1048   1     62696  77 dict of flask.wrappers.Request
<79 more rows. Type e.g. '_.more' to view.>

Partition of a set of 538 objects. Total size = 81920 bytes.
 Index  Count   %     Size   % Cumulative  % Referrers by Kind (class / dict of class)
     0    143  27    16712  20     16712  20 list
     1     30   6    12544  15     29256  36 types.FrameType
     2     83  15    10000  12     39256  48 dict (no owner)
     3    116  22     6592   8     45848  56 tuple
     4      1   0     3352   4     49200  60 __builtin__.cell, dict (no owner), dict of
                                             flask.wrappers.Request, dict of
                                             werkzeug.datastructures.EnvironHeaders, types.FrameType
     5      6   1     1472   2     50672  62 dict of mimetools.Message
     6      2   0     1120   1     51792  63 dict of 0x7f9d02073f00
     7      1   0     1048   1     52840  65 blinker._saferef.BoundMethodWeakref
     8      1   0     1048   1     53888  66 dict of
                                             flask_debugtoolbar.panels.headers.HeaderDebugPanel
     9      1   0     1048   1     54936  67 flask.ctx.RequestContext
<84 more rows. Type e.g. '_.more' to view.>

Hopefully you can see that the dict, str, and tuple usage is much larger with the debug toolbar, and that list objects seem to be holding a large number of references, with dict also in there. Is it possible that the toolbar is holding onto references that isn't being released?

I'm going to investigate a bit more and see if there is anything that stands out in the diffs between the two commits I referenced earlier, and to see if it seems to be an issue with a particular panel.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.