flask-restx icon indicating copy to clipboard operation
flask-restx copied to clipboard

flask-restx is not compatible with the latest werkzeug

Open 12rambau opened this issue 1 year ago • 8 comments

the 2.2.0 release of pallets/werkzeug breaks flask-restx.

Here you can find the following traceback:

../../.local/lib/python3.8/site-packages/flask_restx/__init__.py:5: in <module>
    from .api import Api  # noqa
../../.local/lib/python3.8/site-packages/flask_restx/api.py:50: in <module>
    from .swagger import Swagger
../../.local/lib/python3.8/site-packages/flask_restx/swagger.py:18: in <module>
    from werkzeug.routing import parse_rule
E   ImportError: cannot import name 'parse_rule' from 'werkzeug.routing' (/home/prambaud/.local/lib/python3.8/site-packages/werkzeug/routing/__init__.py)

Repro Steps (if applicable)

  1. install flas-restx
  2. import flask-restx.swagger as frs
  3. Broken!

12rambau avatar Jul 24 '22 23:07 12rambau

parse_rule() is marked as :internal:, shouldn't be used by flask-restx https://github.com/pallets/werkzeug/blob/2.1.x/src/werkzeug/routing.py#L215

bbnil avatar Jul 25 '22 01:07 bbnil

I can confirm the bug

marcszy91 avatar Jul 25 '22 07:07 marcszy91

Can also confirm the bug. Quick workaround is to downgrade Flask to v2.1.2, since the newest version requires Werkzeug >= 2.2.0 and Flask v2.1.2 just requires Werkzeug>=2.0 To prevent the flask requirement from getting the newest version of Werkzeug, it should be listed first in the requirements.txt file. Hope that solves someones issue.

Werkzeug <= 2.1.2   
flask == 2.1.2   
flask-restx >= 0.5.1  

j4asper avatar Jul 25 '22 21:07 j4asper

There is also an issue with flask-restx and werkzeug 2.1.x (https://github.com/python-restx/flask-restx/issues/422) so I would maybe recommend setting werkzeug==2.0.* for now.

peter-doggart avatar Jul 26 '22 12:07 peter-doggart

I put up a PR, #463, which should at least fix this specific problem. It seems there are some cobwebs on the CI for this project, however, so this may require some maintainer love to fix the tests and merge.

plowman avatar Jul 28 '22 22:07 plowman

Now more urgent, with the release of Flask 2.2.0 and its associated update to latest werkzeug.

ptmcg avatar Aug 02 '22 14:08 ptmcg

This error wasted my 30 minutes

It really needs to be fixed asap!

takshch avatar Aug 05 '22 10:08 takshch

have the same issue... also waiting for a fix.

jpiwek avatar Aug 05 '22 10:08 jpiwek

Having this issue as well.... I personally don't mind downgrading, but our pipeline uses a codescanner that will not allow older Werkzeug due to an open CVE

rootVIII avatar Aug 15 '22 14:08 rootVIII

Hi folks,

I am also waiting for a patch: today I tried with these Py Package versions: flask==2.2.2 flask_restx=0.5.1 werkzeug==2.2.2 flask-login==0.6.2

It seems like flask_restx.swagger.py makes issues as werkzeug.routing.rules.py has changed. It doesn't support parse_rule function anymore. Instead there is a new _parse_rule function inside the Rule Class. I had no time to implement the new Werkzeug Rule API into Flask-RestX. However I created two patch files as an interim solution to get everything running again and to make swagger HTML accessible! Please let me know if it works for you.

20220815_flask_restx_patches.tar.gz

jpiwek avatar Aug 15 '22 17:08 jpiwek

Hi unrest folk, because flask-restx is still not compatible with werkzeug I created small monkey patch https://github.com/Ryu-CZ/restx-monkey I am using it at work on company servers, so far so goo. I hope it helps as temporal quick solution for anyone. Enjoy :+1:

PS: It also patches flask_restx.Api soon to be incompatible lazy swagger doc routes binding in case you bind Api with flask.Blueprint first, and register Blueprint into flask app instance flask.Flask later.

Ryu-CZ avatar Aug 26 '22 10:08 Ryu-CZ

@ziirish , will this fix be released as a new version soon? - Thanks

kannanprasanna avatar Sep 19 '22 15:09 kannanprasanna

@kannanprasanna: See #474.

amotl avatar Sep 19 '22 18:09 amotl

So it looks fixed in the sources. Any plan to release a 0.5.2 on pypi ? Thanks.

zogzog avatar Oct 26 '22 15:10 zogzog