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

Dtale not working with Flask 2.2.1 #688

Closed
UFO-101 opened this issue Aug 4, 2022 · 4 comments
Closed

Dtale not working with Flask 2.2.1 #688

UFO-101 opened this issue Aug 4, 2022 · 4 comments

Comments

@UFO-101
Copy link

UFO-101 commented Aug 4, 2022

Exception on /dtale/main/1 [GET]
Traceback (most recent call last):
  File "/Users/user/.local/share/virtualenvs/streamlit-app-26mcmUwo/lib/python3.10/site-packages/flask/app.py", line 2525, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/user/.local/share/virtualenvs/streamlit-app-26mcmUwo/lib/python3.10/site-packages/flask/app.py", line 1822, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/user/.local/share/virtualenvs/streamlit-app-26mcmUwo/lib/python3.10/site-packages/flask/app.py", line 1820, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/user/.local/share/virtualenvs/streamlit-app-26mcmUwo/lib/python3.10/site-packages/flask/app.py", line 1796, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/Users/user/.local/share/virtualenvs/streamlit-app-26mcmUwo/lib/python3.10/site-packages/dtale/views.py", line 1173, in view_main
    return _view_main(data_id)
  File "/Users/user/.local/share/virtualenvs/streamlit-app-26mcmUwo/lib/python3.10/site-packages/dtale/views.py", line 1158, in _view_main
    return base_render_template("dtale/main.html", data_id, title=title, iframe=iframe)
  File "/Users/user/.local/share/virtualenvs/streamlit-app-26mcmUwo/lib/python3.10/site-packages/dtale/views.py", line 1127, in base_render_template
    return render_template(
  File "/Users/user/.local/share/virtualenvs/streamlit-app-26mcmUwo/lib/python3.10/site-packages/flask/templating.py", line 147, in render_template
    return _render(app, template, context)
  File "/Users/user/.local/share/virtualenvs/streamlit-app-26mcmUwo/lib/python3.10/site-packages/flask/templating.py", line 130, in _render
    rv = template.render(context)
  File "/Users/user/.local/share/virtualenvs/streamlit-app-26mcmUwo/lib/python3.10/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/Users/user/.local/share/virtualenvs/streamlit-app-26mcmUwo/lib/python3.10/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/Users/user/.local/share/virtualenvs/streamlit-app-26mcmUwo/lib/python3.10/site-packages/dtale/templates/dtale/main.html", line 1, in top-level template code
    {% extends "dtale/base.html" %}
  File "/Users/user/.local/share/virtualenvs/streamlit-app-26mcmUwo/lib/python3.10/site-packages/dtale/templates/dtale/base.html", line 13, in top-level template code
    <link rel="shortcut icon" href="{{ url_for('static', filename='images/favicon.png') }}">
  File "/Users/user/.local/share/virtualenvs/streamlit-app-26mcmUwo/lib/python3.10/site-packages/dtale/app.py", line 154, in url_for
    return url_for(endpoint, *args, **kwargs)
  File "/Users/user/.local/share/virtualenvs/streamlit-app-26mcmUwo/lib/python3.10/site-packages/flask/helpers.py", line 256, in url_for
    return current_app.url_for(
  File "/Users/user/.local/share/virtualenvs/streamlit-app-26mcmUwo/lib/python3.10/site-packages/dtale/app.py", line 154, in url_for
    return url_for(endpoint, *args, **kwargs)
  File "/Users/user/.local/share/virtualenvs/streamlit-app-26mcmUwo/lib/python3.10/site-packages/flask/helpers.py", line 256, in url_for
    return current_app.url_for(
  File "/Users/user/.local/share/virtualenvs/streamlit-app-26mcmUwo/lib/python3.10/site-packages/dtale/app.py", line 154, in url_for
    return url_for(endpoint, *args, **kwargs)
  File "/Users/user/.local/share/virtualenvs/streamlit-app-26mcmUwo/lib/python3.10/site-packages/flask/helpers.py", line 256, in url_for
    return current_app.url_for(
  File "/Users/user/.local/share/virtualenvs/streamlit-app-26mcmUwo/lib/python3.10/site-packages/dtale/app.py", line 154, in url_for
    return url_for(endpoint, *args, **kwargs)
  File "/Users/user/.local/share/virtualenvs/streamlit-app-26mcmUwo/lib/python3.10/site-packages/flask/helpers.py", line 256, in url_for
    return current_app.url_for(
...
...
...
  File "/.venv/lib/python3.10/site-packages/flask/helpers.py", line 256, in url_for
    return current_app.url_for(
  File "/.venv/lib/python3.10/site-packages/werkzeug/local.py", line 316, in __get__
    obj = instance._get_current_object()  # type: ignore[misc]
  File "/.venv/lib/python3.10/site-packages/werkzeug/local.py", line 507, in _get_current_object
    obj = local.get()  # type: ignore[union-attr]
  RecursionError: maximum recursion depth exceeded while calling a Python object

Dtale is unable to serve any static assets. The browser shows an Internal Server Error 500.

I reproduced this in several environments (Linux, Mac, running in a notebook, as a script inside Streamlit) with the following script.

import dtale
import pandas as pd

if __name__ == '__main__':
    print('Hello World')
    d = dtale.show(pd.DataFrame([1,2,3,4,5]), subprocess=False)
    print('main_url', d._main_url)

The problem appears to be with either the function url_for in dtale/app.py or the function url_for in flask/helpers.py. If you set the app_root parameter the error goes away and the browser shows just a blank screen.

Fixed by downgrading to Flask 2.1.3.

@carb0nc0py
Copy link

I just ran into the same issue. Flask 2.2.1, same error

@tianfy1258
Copy link

tianfy1258 commented Aug 7, 2022

same, but we can solve the problem by "pip install flask==2.1.3"

@aschonfeld
Copy link
Collaborator

Apologies everyone, I've dug in and found that by updating line 155 of dtale/app.py to the following:

return Flask.url_for(self, endpoint, *args, **kwargs)

seems to solve the problem. I'll release a new version soon and let you know when its out there

@aschonfeld
Copy link
Collaborator

@carb0nc0py @tianfy1258 @UFO-101 just released v2.7.1 to pypi (conda-forge available shortly) which fixes this issue. Thanks for spotting this & let me know if you have any other issues. Also, if you have done so already, please toss your ⭐ on the repo. Thanks! 🙏

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

4 participants