dash icon indicating copy to clipboard operation
dash copied to clipboard

[BUG] Flask 2.2.0 unbound_message error.

Open ikoch1978 opened this issue 3 years ago • 5 comments

Describe your context Environment currently running in Docker, with the following Dockerfiles:

Our ubuntu:latest dockerfile:

FROM ubuntu:20.04 ENV DEBIAN_FRONTEND="noninteractive"
LC_ALL="en_US.UTF-8"
LANG="en_US.UTF-8"
LANGUAGE="en_US.UTF-8" RUN apt-get update &&
apt-get upgrade -y &&
apt-get install -y ca-certificates tzdata locales &&
update-ca-certificates -f &&
rm /etc/timezone &&
rm /etc/localtime &&
echo "Europe/Berlin" | tee /etc/timezone &&
ln -s /usr/share/zoneinfo/Europe/Berlin /etc/localtime &&
dpkg-reconfigure --frontend noninteractive tzdata &&
locale-gen en_US.UTF-8 &&
echo "LC_ALL=en_US.UTF8" > /etc/default/locale &&
echo "LANG=en_US.UTF8" >> /etc/default/locale &&
echo "LC_CTYPE=en_US.UTF8" >> /etc/default/locale &&
echo "LC_COLLATE=en_US.UTF8" >> /etc/default/locale &&
chmod 0755 /etc/default/locale

Our python:latest dockerfile:

FROM **/base-images/ubuntu:latest ADD pip.conf /etc/pip.conf ENV REQUESTS_CA_BUNDLE="/etc/ssl/certs/ca-certificates.crt"
PIP_DEFAULT_TIMEOUT=120 RUN apt-get update &&
apt-get install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev curl &&
mkdir /tempdir &&
cd /tempdir &&
curl https://www.python.org/ftp/python/3.10.2/Python-3.10.2.tgz -o python.tgz &&
tar -xvzf python.tgz &&
cd Python-3.10.2 &&
./configure --enable-optimizations &&
make &&
make install &&
cd &&
rm -rf /tempdir &&
python3 -m pip install --upgrade pip &&
pip3 install requests &&
apt-get remove -y curl wget USER app WORKDIR /app ENV PATH="${PATH}:/app/.local/bin/" CMD ["/usr/bin/python3"]

Our dash:latest dockerfile:

FROM **/base-images/python:latest USER root RUN pip3 install dash dash-renderer dash-html-components dash-core-components plotly gunicorn Flask EXPOSE 5000 USER app COPY *.py /app/ CMD ["gunicorn", "--workers", "1", "--bind", "0.0.0.0:5000", "--timeout", "100000", "--max-requests", "20", "--access-logfile", "-", "--error-logfile", "-", "--capture-output", "application:server"]

Our docker file:

FROM **/base-images/dash:latest

EXPOSE 5000 CMD ["gunicorn", "-w", "1", "-b", "0.0.0.0:5000", "-t", "0", "--max-requests", "0", "--access-logfile", "-", "--error-logfile", "-", "--capture-output", "index:server"] USER root COPY requirements.txt /tmp/ RUN pip3 install -r /tmp/requirements.txt &&
rm /tmp/requirements.txt USER app COPY . /app

  • replace the result of pip list | grep dash below
dash                                  2.0.0
dash-bootstrap-components             0.11.4rc3
dash-core-components                  2.0.0
dash-html-components                  2.0.0
dash-table                            5.0.0

Describe the bug

I am not able to start my app, I get the following error:

[2022-08-08 11:24:34 +0200] [1] [INFO] Starting gunicorn 20.0.4 [2022-08-08 11:24:34 +0200] [1] [INFO] Listening at: http://0.0.0.0:5000 (1) [2022-08-08 11:24:34 +0200] [1] [INFO] Using worker: sync [2022-08-08 11:24:34 +0200] [8] [INFO] Booting worker with pid: 8 [2022-08-08 11:24:34 +0200] [9] [INFO] Booting worker with pid: 9 [2022-08-08 11:24:34 +0200] [10] [INFO] Booting worker with pid: 10 [2022-08-08 11:24:34 +0200] [8] [ERROR] Exception in worker process Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/gunicorn/arbiter.py", line 583, in spawn_worker worker.init_process() File "/usr/local/lib/python3.8/dist-packages/gunicorn/workers/base.py", line 119, in init_process self.load_wsgi() File "/usr/local/lib/python3.8/dist-packages/gunicorn/workers/base.py", line 144, in load_wsgi self.wsgi = self.app.wsgi() File "/usr/local/lib/python3.8/dist-packages/gunicorn/app/base.py", line 67, in wsgi self.callable = self.load() File "/usr/local/lib/python3.8/dist-packages/gunicorn/app/wsgiapp.py", line 49, in load return self.load_wsgiapp() File "/usr/local/lib/python3.8/dist-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp return util.import_app(self.app_uri) File "/usr/local/lib/python3.8/dist-packages/gunicorn/util.py", line 358, in import_app mod = importlib.import_module(module) File "/usr/lib/python3.8/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "", line 848, in exec_module File "", line 219, in _call_with_frames_removed File "/app/index.py", line 1, in import dash_bootstrap_components as dbc File "/usr/local/lib/python3.8/dist-packages/dash_bootstrap_components/init.py", line 5, in from dash_bootstrap_components import _components, icons, themes File "/usr/local/lib/python3.8/dist-packages/dash_bootstrap_components/_components/init.py", line 1, in from .Accordion import Accordion File "/usr/local/lib/python3.8/dist-packages/dash_bootstrap_components/_components/Accordion.py", line 3, in from dash.development.base_component import Component, _explicitize_args File "/usr/local/lib/python3.8/dist-packages/dash/init.py", line 5, in from .dependencies import ( # noqa: F401,E402 File "/usr/local/lib/python3.8/dist-packages/dash/dependencies.py", line 4, in from ._validate import validate_callback File "/usr/local/lib/python3.8/dist-packages/dash/_validate.py", line 5, in import flask File "/usr/local/lib/python3.8/dist-packages/flask/init.py", line 4, in from . import json as json File "/usr/local/lib/python3.8/dist-packages/flask/json/init.py", line 8, in from ..globals import current_app File "/usr/local/lib/python3.8/dist-packages/flask/globals.py", line 56, in app_ctx: "AppContext" = LocalProxy( # type: ignore[assignment] TypeError: init() got an unexpected keyword argument 'unbound_message' [2022-08-08 11:24:34 +0200] [8] [INFO] Worker exiting (pid: 8) [2022-08-08 11:24:34 +0200] [9] [ERROR] Exception in worker process Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/gunicorn/arbiter.py", line 583, in spawn_worker worker.init_process() File "/usr/local/lib/python3.8/dist-packages/gunicorn/workers/base.py", line 119, in init_process self.load_wsgi() File "/usr/local/lib/python3.8/dist-packages/gunicorn/workers/base.py", line 144, in load_wsgi self.wsgi = self.app.wsgi() File "/usr/local/lib/python3.8/dist-packages/gunicorn/app/base.py", line 67, in wsgi self.callable = self.load() File "/usr/local/lib/python3.8/dist-packages/gunicorn/app/wsgiapp.py", line 49, in load return self.load_wsgiapp() File "/usr/local/lib/python3.8/dist-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp return util.import_app(self.app_uri) File "/usr/local/lib/python3.8/dist-packages/gunicorn/util.py", line 358, in import_app mod = importlib.import_module(module) File "/usr/lib/python3.8/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "", line 848, in exec_module File "", line 219, in _call_with_frames_removed File "/app/index.py", line 1, in import dash_bootstrap_components as dbc File "/usr/local/lib/python3.8/dist-packages/dash_bootstrap_components/init.py", line 5, in from dash_bootstrap_components import _components, icons, themes File "/usr/local/lib/python3.8/dist-packages/dash_bootstrap_components/_components/init.py", line 1, in from .Accordion import Accordion File "/usr/local/lib/python3.8/dist-packages/dash_bootstrap_components/_components/Accordion.py", line 3, in from dash.development.base_component import Component, _explicitize_args File "/usr/local/lib/python3.8/dist-packages/dash/init.py", line 5, in from .dependencies import ( # noqa: F401,E402 File "/usr/local/lib/python3.8/dist-packages/dash/dependencies.py", line 4, in from ._validate import validate_callback File "/usr/local/lib/python3.8/dist-packages/dash/_validate.py", line 5, in import flask File "/usr/local/lib/python3.8/dist-packages/flask/init.py", line 4, in from . import json as json File "/usr/local/lib/python3.8/dist-packages/flask/json/init.py", line 8, in from ..globals import current_app File "/usr/local/lib/python3.8/dist-packages/flask/globals.py", line 56, in app_ctx: "AppContext" = LocalProxy( # type: ignore[assignment] TypeError: init() got an unexpected keyword argument 'unbound_message' [2022-08-08 11:24:34 +0200] [9] [INFO] Worker exiting (pid: 9) [2022-08-08 11:24:34 +0200] [10] [ERROR] Exception in worker process Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/gunicorn/arbiter.py", line 583, in spawn_worker worker.init_process() File "/usr/local/lib/python3.8/dist-packages/gunicorn/workers/base.py", line 119, in init_process self.load_wsgi() File "/usr/local/lib/python3.8/dist-packages/gunicorn/workers/base.py", line 144, in load_wsgi self.wsgi = self.app.wsgi() File "/usr/local/lib/python3.8/dist-packages/gunicorn/app/base.py", line 67, in wsgi self.callable = self.load() File "/usr/local/lib/python3.8/dist-packages/gunicorn/app/wsgiapp.py", line 49, in load return self.load_wsgiapp() File "/usr/local/lib/python3.8/dist-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp return util.import_app(self.app_uri) File "/usr/local/lib/python3.8/dist-packages/gunicorn/util.py", line 358, in import_app mod = importlib.import_module(module) File "/usr/lib/python3.8/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "", line 848, in exec_module File "", line 219, in _call_with_frames_removed File "/app/index.py", line 1, in import dash_bootstrap_components as dbc File "/usr/local/lib/python3.8/dist-packages/dash_bootstrap_components/init.py", line 5, in from dash_bootstrap_components import _components, icons, themes File "/usr/local/lib/python3.8/dist-packages/dash_bootstrap_components/_components/init.py", line 1, in from .Accordion import Accordion File "/usr/local/lib/python3.8/dist-packages/dash_bootstrap_components/_components/Accordion.py", line 3, in from dash.development.base_component import Component, _explicitize_args File "/usr/local/lib/python3.8/dist-packages/dash/init.py", line 5, in from .dependencies import ( # noqa: F401,E402 File "/usr/local/lib/python3.8/dist-packages/dash/dependencies.py", line 4, in from ._validate import validate_callback File "/usr/local/lib/python3.8/dist-packages/dash/_validate.py", line 5, in import flask File "/usr/local/lib/python3.8/dist-packages/flask/init.py", line 4, in from . import json as json File "/usr/local/lib/python3.8/dist-packages/flask/json/init.py", line 8, in from ..globals import current_app File "/usr/local/lib/python3.8/dist-packages/flask/globals.py", line 56, in app_ctx: "AppContext" = LocalProxy( # type: ignore[assignment] TypeError: init() got an unexpected keyword argument 'unbound_message' [2022-08-08 11:24:34 +0200] [10] [INFO] Worker exiting (pid: 10) Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/gunicorn/arbiter.py", line 202, in run self.manage_workers() File "/usr/local/lib/python3.8/dist-packages/gunicorn/arbiter.py", line 545, in manage_workers self.spawn_workers() File "/usr/local/lib/python3.8/dist-packages/gunicorn/arbiter.py", line 617, in spawn_workers time.sleep(0.1 * random.random()) File "/usr/local/lib/python3.8/dist-packages/gunicorn/arbiter.py", line 242, in handle_chld self.reap_workers() File "/usr/local/lib/python3.8/dist-packages/gunicorn/arbiter.py", line 525, in reap_workers raise HaltServer(reason, self.WORKER_BOOT_ERROR) gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>

Expected behavior

Starting of the server and listening to port in localhost.

Thank you very much for the help!

ikoch1978 avatar Aug 08 '22 09:08 ikoch1978

This line is the error:

got an unexpected keyword argument 'unbound_message'

Related to flask 2.2.0, you can pin earlier version of flask to fix the issue in the meantime.

T4rk1n avatar Aug 09 '22 13:08 T4rk1n

Generally though people are able to use Dash with Flask 2.2 (eg https://github.com/plotly/dash/issues/2177) - so is there something else required to generate this problem, some other pinned dependency?

alexcjohnson avatar Aug 09 '22 16:08 alexcjohnson

It's werkzeug version mismatch, flask 2.2.x needs werkzeug 2.2.x

T4rk1n avatar Aug 09 '22 17:08 T4rk1n

I've also had a report of this error coming up with a slightly different stack trace:

“Traceback (most recent call last):
  File "/workspace/app.py", line 2, in <module>
    import dash
  File "/app/.heroku/python/lib/python3.9/site-packages/dash/__init__.py", line 5, in <module>
    from .dash import Dash, no_update  # noqa: F401,E402
  File "/app/.heroku/python/lib/python3.9/site-packages/dash/dash.py", line 17, in <module>
    import flask
  File "/app/.heroku/python/lib/python3.9/site-packages/flask/__init__.py", line 4, in <module>
    from . import json as json
  File "/app/.heroku/python/lib/python3.9/site-packages/flask/json/__init__.py", line 8, in <module>
    from ..globals import current_app
  File "/app/.heroku/python/lib/python3.9/site-packages/flask/globals.py", line 56, in <module>
    app_ctx: "AppContext" = LocalProxy(  # type: ignore[assignment]
TypeError: __init__() got an unexpected keyword argument 'unbound_message'”

Downgrading Flask resolved this. @T4rk1n do you think this is the same version mismatch problem?

hannahker avatar Aug 11 '22 18:08 hannahker

@hannahker Yes, this happen when flask 2.2.x is installed but not werkzeug, possibly because werkzeug version was locked in requirements.txt but not flask

T4rk1n avatar Aug 11 '22 19:08 T4rk1n