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

Werkzeug V1.x breaks restx import #34

Closed
PaulWaldo opened this issue Feb 6, 2020 · 8 comments · Fixed by #35
Closed

Werkzeug V1.x breaks restx import #34

PaulWaldo opened this issue Feb 6, 2020 · 8 comments · Fixed by #35
Labels
bug Something isn't working

Comments

@PaulWaldo
Copy link

***** BEFORE LOGGING AN ISSUE *****

  • Is this something you can debug and fix? Send a pull request! Bug fixes and documentation fixes are welcome.
  • Please check if a similar issue already exists or has been closed before. Seriously, nobody here is getting paid. Help us out and take five minutes to make sure you aren't submitting a duplicate.
  • Please review the guidelines for contributing

Code

from flask_restx import Api

Repro Steps (if applicable)

  1. Use this Pipfile
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
#flask-restplus = "*"
flask-restx = "*"
flask = "*"

[requires]
python_version = "3.7"
  1. Pipenv install
  2. Attempt to import Api from restx
paul-> python 
Python 3.7.6 (default, Dec 30 2019, 19:38:28) 
[Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from flask_restx import Api
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/paul/.local/share/virtualenvs/restplus-test-_yVwyWWD/lib/python3.7/site-packages/flask_restx/__init__.py", line 5, in <module>
    from .api import Api  # noqa
  File "/Users/paul/.local/share/virtualenvs/restplus-test-_yVwyWWD/lib/python3.7/site-packages/flask_restx/api.py", line 28, in <module>
    from werkzeug import cached_property
ImportError: cannot import name 'cached_property' from 'werkzeug' (/Users/paul/.local/share/virtualenvs/restplus-test-_yVwyWWD/lib/python3.7/site-packages/werkzeug/__init__.py)
>>> 
  1. Broken!

Expected Behavior

Api should be silently imported

Actual Behavior

Import fails with error below

Error Messages/Stack Trace

Traceback (most recent call last):
File "", line 1, in
File "/Users/paul/.local/share/virtualenvs/restplus-test-_yVwyWWD/lib/python3.7/site-packages/flask_restx/init.py", line 5, in
from .api import Api # noqa
File "/Users/paul/.local/share/virtualenvs/restplus-test-_yVwyWWD/lib/python3.7/site-packages/flask_restx/api.py", line 28, in
from werkzeug import cached_property
ImportError: cannot import name 'cached_property' from 'werkzeug' (/Users/paul/.local/share/virtualenvs/restplus-test-_yVwyWWD/lib/python3.7/site-packages/werkzeug/init.py)

Environment

  • Python version 3.7.6
paul-> pipenv graph
flask-restx==0.1.0
  - aniso8601 [required: >=0.82, installed: 8.0.0]
  - Flask [required: >=0.8, installed: 1.1.1]
    - click [required: >=5.1, installed: 7.0]
    - itsdangerous [required: >=0.24, installed: 1.1.0]
    - Jinja2 [required: >=2.10.1, installed: 2.11.1]
      - MarkupSafe [required: >=0.23, installed: 1.1.1]
    - Werkzeug [required: >=0.15, installed: 1.0.0]
  - jsonschema [required: Any, installed: 3.2.0]
    - attrs [required: >=17.4.0, installed: 19.3.0]
    - importlib-metadata [required: Any, installed: 1.5.0]
      - zipp [required: >=0.5, installed: 2.1.0]
    - pyrsistent [required: >=0.14.0, installed: 0.15.7]
      - six [required: Any, installed: 1.14.0]
    - setuptools [required: Any, installed: 45.1.0]
    - six [required: >=1.11.0, installed: 1.14.0]
  - pytz [required: Any, installed: 2019.3]
  - six [required: >=1.3.0, installed: 1.14.0]
  • Flask version
  • Flask-RESTX version
  • Other installed Flask extensions

Additional Context

This also occurs using flask-restplus. My guess is that the latest Flask breaks both.

@PaulWaldo PaulWaldo added the bug Something isn't working label Feb 6, 2020
@ziirish
Copy link
Contributor

ziirish commented Feb 6, 2020

Thanks for the report.
I thought I gave this a look already, but it looks like I missed something.

There is indeed one missing rename here flask_restx/api.py:28:from werkzeug import cached_property

@FireByTrial
Copy link

FireByTrial commented Feb 7, 2020

could it just be pinned at werkzeug<=0.16.1 for now at least? kind of like commented here noirbizarre/flask-restplus#777

@ziirish
Copy link
Contributor

ziirish commented Feb 7, 2020

Yes, I'll do this as a quick hotfix for now.

@ziirish
Copy link
Contributor

ziirish commented Feb 8, 2020

flask-restx 0.1.1 is now available and workarounds the issue by pinning werkzeug.

The proper fix will be part of a longer-term plan explained in #37.

@5hirish
Copy link

5hirish commented Feb 8, 2020

flask-restx 0.1.1 doesn't seem to have fixed the issue. So, had to pin werkzeug in project requirements too.

@ziirish
Copy link
Contributor

ziirish commented Feb 8, 2020

Hm, sorry but I cannot reproduce the issue.
Do you have an example?

pip install flask-restx
[...]
Successfully installed Flask-1.1.1 Jinja2-2.11.1 MarkupSafe-1.1.1 aniso8601-8.0.0 attrs-19.3.0 click-7.0 flask-restx-0.1.1 importlib-metadata-1.5.0 itsdangerous-1.1.0 jsonschema-3.2.0 pyrsistent-0.15.7 pytz-2019.3 six-1.14.0 werkzeug-0.16.1 zipp-2.2.0


FLASK_APP=todo.py:app flask run --port 5555
 * Serving Flask app "todo.py:app"
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5555/ (Press CTRL+C to quit)
127.0.0.1 - - [08/Feb/2020 21:06:07] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [08/Feb/2020 21:06:08] "GET /swaggerui/swagger-ui.css HTTP/1.1" 200 -
127.0.0.1 - - [08/Feb/2020 21:06:08] "GET /swaggerui/droid-sans.css HTTP/1.1" 200 -
127.0.0.1 - - [08/Feb/2020 21:06:08] "GET /swaggerui/swagger-ui-standalone-preset.js HTTP/1.1" 200 -
127.0.0.1 - - [08/Feb/2020 21:06:08] "GET /swaggerui/swagger-ui-bundle.js HTTP/1.1" 200 -
127.0.0.1 - - [08/Feb/2020 21:06:08] "GET /swaggerui/favicon-16x16.png HTTP/1.1" 200 -
127.0.0.1 - - [08/Feb/2020 21:06:08] "GET /swagger.json HTTP/1.1" 200 -
127.0.0.1 - - [08/Feb/2020 21:06:18] "GET /todos/ HTTP/1.1" 200 -

@5hirish
Copy link

5hirish commented Feb 9, 2020

Seems like this in my requirements.txt might be causing the issue:

flask==1.1.1
flask-restx==0.1.1

So, this issue comes up in my docker as I might have added flask explicitly in my requirements.txt:

pip install flask
Requirement already satisfied: flask in ./env/lib/python3.6/site-packages (1.1.1)
Requirement already satisfied: click>=5.1 in ./env/lib/python3.6/site-packages (from flask) (7.0)
Requirement already satisfied: itsdangerous>=0.24 in ./env/lib/python3.6/site-packages (from flask) (1.1.0)
Requirement already satisfied: Jinja2>=2.10.1 in ./env/lib/python3.6/site-packages (from flask) (2.10.1)
Requirement already satisfied: Werkzeug>=0.15 in ./env/lib/python3.6/site-packages (from flask) (0.15.6)
Requirement already satisfied: MarkupSafe>=0.23 in ./env/lib/python3.6/site-packages (from Jinja2>=2.10.1->flask) (1.1.1)

Note: This is after pinning hence werkzeug is at 0.15.6 but if not pinned then in docker it installs the latest version.
Also, a huge thanks to all contributors and @ziirish for reviving this project!

royragsdale added a commit to royragsdale/picoCTF that referenced this issue Feb 12, 2020
Should be temporary. Should also consider transition to flask_restx as
flask_restplus is currently unmaintained.

reference:
noirbizarre/flask-restplus#777
python-restx/flask-restx#39
python-restx/flask-restx#34

notice from flask_restplus: https://github.com/noirbizarre/flask-restplus#flask-restplus
"This project has been forked to Flask-RESTX and will be maintained by
by the python-restx organization. Flask-RESTPlus should be considered
unmaintained."
royragsdale added a commit to royragsdale/picoCTF that referenced this issue Feb 12, 2020
Should be temporary. Should also consider transition to flask_restx as
flask_restplus is currently unmaintained.

reference:
noirbizarre/flask-restplus#777
python-restx/flask-restx#39
python-restx/flask-restx#34

notice from flask_restplus: https://github.com/noirbizarre/flask-restplus#flask-restplus
"This project has been forked to Flask-RESTX and will be maintained by
by the python-restx organization. Flask-RESTPlus should be considered
unmaintained."
@ziirish
Copy link
Contributor

ziirish commented Feb 13, 2020

@5hirish I'm afraid there is nothing we can do about this then. It is either a bug or a feature of pip.

I'm now closing this issue since we hotfixed it. The long-term fix will be tracked in #37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants