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

ProfilerMiddleware's default filename_format causes ValueError when ProfilerMiddleware is used with profile_dir #1511

Closed
jlove-bazaarvoice opened this issue Apr 10, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@jlove-bazaarvoice
Copy link

commented Apr 10, 2019

Environment

$ sw_vers 
ProductName:	Mac OS X
ProductVersion:	10.13.6
BuildVersion:	17G3025

$ python --version
Python 3.7.2

$ pip freeze
Click==7.0
Flask==1.0.2
itsdangerous==1.1.0
Jinja2==2.10.1
MarkupSafe==1.1.1
Werkzeug==0.15.2

Basically, the only Python dependency I installed was Flask because that's what I'm most familiar with. However, the error I'm describing looks to be contained within werkzeug.

Observed Behavior

When using ProfilerMiddleware with its profile_dir argument, the following error gets raised after a request is sent to the server:

Error on request:
Traceback (most recent call last):
  File "/dev/jlove-bazaarvoice/werkzeug-profiler-bug/.venv/lib/python3.7/site-packages/werkzeug/serving.py", line 302, in run_wsgi
    execute(self.server.app)
  File "/dev/jlove-bazaarvoice/werkzeug-profiler-bug/.venv/lib/python3.7/site-packages/werkzeug/serving.py", line 290, in execute
    application_iter = app(environ, start_response)
  File "/dev/jlove-bazaarvoice/werkzeug-profiler-bug/.venv/lib/python3.7/site-packages/flask/app.py", line 2309, in __call__
    return self.wsgi_app(environ, start_response)
  File "/dev/jlove-bazaarvoice/werkzeug-profiler-bug/.venv/lib/python3.7/site-packages/werkzeug/middleware/profiler.py", line 119, in __call__
    time=time.time(),
ValueError: Unknown format code 'd' for object of type 'float'

Expected Behavior

No ValueError.

Steps to Reproduce

  1. pip install flask
  2. Save the following file as app.py.
# app.py
from flask import Flask
from werkzeug.middleware.profiler import ProfilerMiddleware

app = Flask(__name__)
app.wsgi_app = ProfilerMiddleware(app.wsgi_app, profile_dir=".")


@app.route("/", methods=["GET"])
def get_index():
    return "Hello, world!"
  1. Start the server with FLASK_APP=app.py flask run.
  2. Send a request to the server (e.g. http://127.0.0.1:5000/).

Workaround/Solution

Slightly modify ProfilerMiddleware's filename_format, replacing the d with f. For example:

app.wsgi_app = ProfilerMiddleware(
    app.wsgi_app, profile_dir=".", filename_format="{method}.{path}.{elapsed:06f}ms.{time:f}.prof"
)

Both instances of d need to be replaced because both elapsed and time are floating point numbers.

@davidism

This comment has been minimized.

Copy link
Member

commented Apr 10, 2019

@jlove-bazaarvoice

This comment has been minimized.

Copy link
Author

commented Apr 10, 2019

Dangit. After all the work I put into this issue, it's a dupe. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.