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

AttributeError: 'ProfilerDebugPanel' object has no attribute 'dump_filename' #286

Open
mconigliaro opened this issue Sep 13, 2024 · 4 comments · May be fixed by #294
Open

AttributeError: 'ProfilerDebugPanel' object has no attribute 'dump_filename' #286

mconigliaro opened this issue Sep 13, 2024 · 4 comments · May be fixed by #294

Comments

@mconigliaro
Copy link

I enable the profiler and this happens:

Traceback (most recent call last):
  File "/Users/mike/Developer/other/test/test-flask/.venv/lib/python3.12/site-packages/flask/app.py", line 1498, in __call__
    return self.wsgi_app(environ, start_response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mike/Developer/other/test/test-flask/.venv/lib/python3.12/site-packages/flask/app.py", line 1476, in wsgi_app
    response = self.handle_exception(e)
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mike/Developer/other/test/test-flask/.venv/lib/python3.12/site-packages/flask/app.py", line 1473, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mike/Developer/other/test/test-flask/.venv/lib/python3.12/site-packages/flask/app.py", line 883, in full_dispatch_request
    return self.finalize_request(rv)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mike/Developer/other/test/test-flask/.venv/lib/python3.12/site-packages/flask/app.py", line 904, in finalize_request
    response = self.process_response(response)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mike/Developer/other/test/test-flask/.venv/lib/python3.12/site-packages/flask/app.py", line 1281, in process_response
    response = self.ensure_sync(func)(response)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mike/Developer/other/test/test-flask/.venv/lib/python3.12/site-packages/flask_debugtoolbar/__init__.py", line 248, in process_response
    panel.process_response(real_request, response)
  File "/Users/mike/Developer/other/test/test-flask/.venv/lib/python3.12/site-packages/flask_debugtoolbar/panels/profiler.py", line 96, in process_response
    if self.dump_filename:
       ^^^^^^^^^^^^^^^^^^^
AttributeError: 'ProfilerDebugPanel' object has no attribute 'dump_filename'

I have to clear my cookies to make the error go away.

Environment:

  • Python version: Python 3.12.5
  • Flask-DebugToolbar version: 0.15.1
  • Flask version: 3.0.3
@mconigliaro
Copy link
Author

According to the code, self.dump_filename doesn't get set unless DEBUG_TB_PROFILER_ENABLED is True. But if I enable that, I get this:

Traceback (most recent call last):
  File "/Users/mike/Developer/other/test/test-flask/.venv/lib/python3.12/site-packages/flask/app.py", line 1498, in __call__
    return self.wsgi_app(environ, start_response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mike/Developer/other/test/test-flask/.venv/lib/python3.12/site-packages/flask/app.py", line 1476, in wsgi_app
    response = self.handle_exception(e)
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mike/Developer/other/test/test-flask/.venv/lib/python3.12/site-packages/flask/app.py", line 1473, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mike/Developer/other/test/test-flask/.venv/lib/python3.12/site-packages/flask/app.py", line 882, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mike/Developer/other/test/test-flask/.venv/lib/python3.12/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mike/Developer/other/test/test-flask/.venv/lib/python3.12/site-packages/flask_debugtoolbar/__init__.py", line 149, in dispatch_request
    return view_func(**req.view_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.5/Frameworks/Python.framework/Versions/3.12/lib/python3.12/cProfile.py", line 109, in runcall
    self.enable()
ValueError: Another profiling tool is already active

@liaosf
Copy link

liaosf commented Sep 25, 2024

Set environment variant to resolve the issues like "no attribute 'dump_filename' ".
DEBUG_TB_PROFILER_ENABLED = True
DEBUG_TB_DUMP_FILENAME_FORMAT = {request.url} # other setting like: {request.method}, {request.path}

@trupka
Copy link

trupka commented Sep 29, 2024

It seems that ProfilerDebugPanel().dump_filename attribute is undefined when DEBUG_TB_PROFILER_ENABLED != True.
Possible solution is to modify __init__(self, jinja_env, context={}) method, someting like:

diff --git a/.venv/Lib/site-packages/flask_debugtoolbar/panels/profiler.py b/.venv/Lib/site-packages/flask_debugtoolbar/panels/profiler.py
--- a/.venv/Lib/site-packages/flask_debugtoolbar/panels/profiler.py	
+++ b/.venv/Lib/site-packages/flask_debugtoolbar/panels/profiler.py	(date 1727604243564)
@@ -27,6 +27,8 @@
             self.dump_filename = current_app.config.get(
                 "DEBUG_TB_PROFILER_DUMP_FILENAME"
             )
+        else:
+            self.dump_filename = None
 
     def has_content(self):
         return bool(self.profiler)

@jeffwidman
Copy link
Member

Feel free to submit a PR with your suggested fix.

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

Successfully merging a pull request may close this issue.

4 participants