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
Milestone

Comments

@jlove-bazaarvoice
Copy link

@jlove-bazaarvoice jlove-bazaarvoice 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
Copy link
Member

@davidism davidism commented Apr 10, 2019

@jlove-bazaarvoice
Copy link
Author

@jlove-bazaarvoice jlove-bazaarvoice commented Apr 10, 2019

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

@davidism davidism added this to the 0.15.3 milestone May 8, 2019
@davidism davidism closed this May 12, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants