dathere / datapusher-plus-docker

MIT License
10 stars 4 forks source link

ImportError: cannot import name '_request_ctx_stack' from 'flask' - Flask 3 issue(?) #10

Open twdbben opened 11 months ago

twdbben commented 11 months ago

I am trying to run datapusher-plus-docker, but after doing a successful docker compose build, when I do docker compose up, I get the following error.

datapusher-plus  | Traceback (most recent call last):
datapusher-plus  |   File "/srv/app/src/datapusher-plus/datapusher/wsgi.py", line 2, in <module>
datapusher-plus  |   File "/srv/app/src/datapusher-plus/datapusher/wsgi.py", line 2, in <module>
datapusher-plus  | Traceback (most recent call last):
datapusher-plus  |   File "/srv/app/src/datapusher-plus/datapusher/wsgi.py", line 2, in <module>
datapusher-plus  |     import ckanserviceprovider.web as web
datapusher-plus  |     import ckanserviceprovider.web as web
datapusher-plus  |   File "/usr/lib/ckan/dpplus_venv/lib/python3.10/site-packages/ckanserviceprovider/web.py", line 13, in <module>
datapusher-plus  |   File "/usr/lib/ckan/dpplus_venv/lib/python3.10/site-packages/ckanserviceprovider/web.py", line 13, in <module>
datapusher-plus  |     import flask_login as flogin
datapusher-plus  |     import flask_login as flogin
datapusher-plus  |   File "/usr/lib/ckan/dpplus_venv/lib/python3.10/site-packages/flask_login/__init__.py", line 12, in <module>
datapusher-plus  |   File "/usr/lib/ckan/dpplus_venv/lib/python3.10/site-packages/flask_login/__init__.py", line 12, in <module>
datapusher-plus  |     import ckanserviceprovider.web as web
datapusher-plus  |   File "/usr/lib/ckan/dpplus_venv/lib/python3.10/site-packages/ckanserviceprovider/web.py", line 13, in <module>
datapusher-plus  |     from .login_manager import LoginManager
datapusher-plus  |   File "/usr/lib/ckan/dpplus_venv/lib/python3.10/site-packages/flask_login/login_manager.py", line 5, in <module>
datapusher-plus  |     import flask_login as flogin
datapusher-plus  |     from flask import _request_ctx_stack
datapusher-plus  | ImportError: cannot import name '_request_ctx_stack' from 'flask' (/usr/lib/ckan/dpplus_venv/lib/python3.10/site-packages/flask/__init__.py)
datapusher-plus  | unable to load app 0 (mountpoint='') (callable not found or import error)

Based on this discussion I found, https://stackoverflow.com/questions/77240858/how-to-fix-cannot-import-name-request-ctx-stack-from-flask, it seems like it might be related to Flask having updated to version 3.

If I do a docker exec -it da030eb77625 bash into my running container and then . /usr/lib/ckan/dpplus_venv/bin/activate and finally a pip list, I get the following list of installed packages in my datapusher-plus-docker container:

Package             Version      Editable project location
------------------- ------------ ----------------------------
APScheduler         3.9.1.post1
blinker             1.7.0
certifi             2023.11.17
charset-normalizer  3.3.2
ckanserviceprovider 1.1.0
click               8.1.7
coverage            7.3.3
datapusher-plus     0.15.0       /srv/app/src/datapusher-plus
datasize            1.0.0
exceptiongroup      1.2.0
Flask               3.0.0
Flask-Login         0.6.0
future              0.18.3
httpretty           1.1.4
idna                3.6
iniconfig           2.0.0
itsdangerous        2.1.2
Jinja2              3.1.2
MarkupSafe          2.1.3
packaging           23.2
pip                 22.0.2
pluggy              1.3.0
psycopg2-binary     2.9.9
pytest              7.4.3
pytest-cov          4.1.0
python-dateutil     2.8.2
python-dotenv       1.0.0
pytz                2023.3.post1
requests            2.31.0
semver              3.0.2
setuptools          59.6.0
six                 1.16.0
SQLAlchemy          1.3.24
tomli               2.0.1
tzdata              2023.3
tzlocal             5.2
urllib3             2.1.0
uWSGI               2.0.23
Werkzeug            3.0.1

Do you know if datapusher-plus-docker should work with Flask 3? If not, do you know how I can pin flask back to 2.3.2 within the datapusher-plus-docker config, and are there any other dependencies that need to be pinned?

Thanks for any advice you can provide on my situation.

twdbben commented 11 months ago

There may be a better way to do this, but I solved this issue by adding

RUN ${VENV}/bin/pip install flask==2.3.2
RUN ${VENV}/bin/pip install uwsgi==2.0.21
RUN ${VENV}/bin/pip install werkzeug==2.3.6

at line 82 of datapusher-plus/0.15.0/Dockerfile

L-Har commented 2 months ago

I'm seeing this issue as well and your solution worked.