Werkzeug: Version 1.0.0 removed previously deprecated code

Created on 6 Feb 2020  ·  22Comments  ·  Source: pallets/werkzeug

The 1.0.0 release that was pushed 2 hours ago published breaking changes for people using flask. Not sure if it was a desired effect and flask should pin their version or if changes in this project need to happen.

Most helpful comment

This is a completely awful user experience. Flask-WTF 0.14.3 with the fixes was released hours ago. How are we pushing out a release that removes support when massive parts of the ecosystem were not ready for this?

This is I believe the third time an update to one of the pallets libraries broke code I had running in less than six months.

All 22 comments

Please post full tracebacks if you encounter any issues.

The issue is not with Flask, and Werkzeug will not continue supporting these deprecated imports. 0.16 has been issuing deprecation warnings for 5 months. Use that version as an intermediate step to identify what imports have changed.

You can help extensions and other projects by opening an issue or submitting a PR in the relevant project.

  • Flask-Admin 1.5.5
  • Flask-Babel 1.0
  • Flask-BabelEx 0.9.4
  • flask-restplus (not merged, unmaintained in favor of flask-restx)
  • flask-restx (merged, not released yet)
  • Flask-Testing 0.8.0
  • Flask-WTF 0.14.3
  • django-extensions 2.2.8
  • pytest-flask 0.15.1
Traceback (most recent call last):
  File "/usr/local/bin/pytest", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py", line 73, in main
    config = _prepareconfig(args, plugins)
  File "/usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py", line 224, in _prepareconfig
    pluginmanager=pluginmanager, args=args
  File "/usr/local/lib/python3.7/site-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/usr/local/lib/python3.7/site-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/usr/local/lib/python3.7/site-packages/pluggy/manager.py", line 87, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "/usr/local/lib/python3.7/site-packages/pluggy/callers.py", line 203, in _multicall
    gen.send(outcome)
  File "/usr/local/lib/python3.7/site-packages/_pytest/helpconfig.py", line 89, in pytest_cmdline_parse
    config = outcome.get_result()
  File "/usr/local/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/local/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py", line 794, in pytest_cmdline_parse
    self.parse(args)
  File "/usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py", line 1000, in parse
    self._preparse(args, addopts=addopts)
  File "/usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py", line 948, in _preparse
    self.pluginmanager.load_setuptools_entrypoints("pytest11")
  File "/usr/local/lib/python3.7/site-packages/pluggy/manager.py", line 299, in load_setuptools_entrypoints
    plugin = ep.load()
  File "/usr/local/lib/python3.7/site-packages/importlib_metadata/__init__.py", line 94, in load
    module = import_module(match.group('module'))
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "/usr/local/lib/python3.7/site-packages/_pytest/assertion/rewrite.py", line 143, in exec_module
    exec(co, module.__dict__)
  File "/usr/local/lib/python3.7/site-packages/pytest_flask/plugin.py", line 14, in <module>
    from werkzeug import cached_property
ImportError: cannot import name 'cached_property' from 'werkzeug' (/usr/local/lib/python3.7/site-packages/werkzeug/__init__.py)

That's pytest-flask, you'll want to contact them. Looks like pytest-flask 0.15.1 has already been released with a fix.

+1, having the following issue:
packages/flask_wtf/recaptcha/widgets.py", line 5, in <module> from werkzeug import url_encode ImportError: cannot import name 'url_encode'

+1 this newest release is also breaking our dependencies. Seems like its a V1.0.0 issue

```Traceback (most recent call last):
File "/home/ec2-user/butter_web/venv/lib64/python3.6/site-packages/flask/cli.py", line 240, in locate_app
__import__(module_name)
File "/home/ec2-user/butter_web/butter.py", line 1, in
from app import app, db
File "/home/ec2-user/butter_web/app/__init__.py", line 8, in
from flask_admin.contrib.sqla import ModelView
File "/home/ec2-user/butter_web/venv/lib64/python3.6/site-packages/flask_admin/contrib/sqla/__init__.py", line 2, in
from .view import ModelView
File "/home/ec2-user/butter_web/venv/lib64/python3.6/site-packages/flask_admin/contrib/sqla/view.py", line 19, in
from flask_admin.model import BaseModelView
File "/home/ec2-user/butter_web/venv/lib64/python3.6/site-packages/flask_admin/model/__init__.py", line 2, in
from .base import BaseModelView
File "/home/ec2-user/butter_web/venv/lib64/python3.6/site-packages/flask_admin/model/base.py", line 8, in
from werkzeug import secure_filename
ImportError: cannot import name 'secure_filename'

Whats the solution here? Explicitly locking 0.16.1 does not resolve this.

@tjohnson4 See my comment above for what to do. The error you posted on the Flask issue was unrelated.

This is a completely awful user experience. Flask-WTF 0.14.3 with the fixes was released hours ago. How are we pushing out a release that removes support when massive parts of the ecosystem were not ready for this?

This is I believe the third time an update to one of the pallets libraries broke code I had running in less than six months.

similar issue

Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/ubuntu/swagger-codegen/samples/server/petstore/flaskConnexion/swagger_server/__main__.py", line 3, in <module>
    import connexion
  File "/home/ubuntu/.local/lib/python3.6/site-packages/connexion/__init__.py", line 3, in <module>
    from .apis import AbstractAPI  # NOQA
  File "/home/ubuntu/.local/lib/python3.6/site-packages/connexion/apis/__init__.py", line 1, in <module>
    from .abstract import AbstractAPI  # NOQA
  File "/home/ubuntu/.local/lib/python3.6/site-packages/connexion/apis/abstract.py", line 14, in <module>
    from ..operation import Operation
  File "/home/ubuntu/.local/lib/python3.6/site-packages/connexion/operation.py", line 7, in <module>
    from .decorators import validation
  File "/home/ubuntu/.local/lib/python3.6/site-packages/connexion/decorators/validation.py", line 9, in <module>
    from werkzeug import FileStorage
ImportError: cannot import name 'FileStorage'

workaround
add werkzeug == 0.16.1 to requirements.txt solved it for me

@Abdelsalam-Abbas connexion fixed that import back in October 2019 - maybe you are running an old version?
https://github.com/zalando/connexion/releases/tag/2.4.0

If your Flask-Session is broken:

File "/usr/local/lib/python3.8/site-packages/flask_session/__init__.py", line 61, in init_app                                                                                                                                                                                                                               
    app.session_interface = self._get_interface(app)                                                                                                                                                                                                                                                                          
  File "/usr/local/lib/python3.8/site-packages/flask_session/__init__.py", line 90, in _get_interface                                                                                                                                                                                                                         
    session_interface = FileSystemSessionInterface(                                                                                                                                                                                                                                                                           
  File "/usr/local/lib/python3.8/site-packages/flask_session/sessions.py", line 313, in __init__                                                                                                                                                                                                                              
    from werkzeug.contrib.cache import FileSystemCache                                                                                                                                                                                                                                                                        
ModuleNotFoundError: No module named 'werkzeug.contrib'  

Add werkzeug == 0.16.1 to requirements.txt solved it for me

If your Flask-RestPlus is broken:

Traceback (most recent call last):
  File "/export/home/hysdsops/sciflo/lib/python3.7/site-packages/flask/cli.py", line 240, in locate_app
    __import__(module_name)
  File "/export/home/hysdsops/sciflo/ops/pele/app.py", line 4, in <module>
    from pele import create_app, db
  File "/export/home/hysdsops/sciflo/ops/pele/pele/__init__.py", line 5, in <module>
    from flask_restplus import apidoc
  File "/export/home/hysdsops/sciflo/lib/python3.7/site-packages/flask_restplus/__init__.py", line 4, in <module>
    from . import fields, reqparse, apidoc, inputs, cors
  File "/export/home/hysdsops/sciflo/lib/python3.7/site-packages/flask_restplus/fields.py", line 17, in <module>
    from werkzeug import cached_property
ImportError: cannot import name 'cached_property' from 'werkzeug' (/export/home/hysdsops/sciflo/lib/python3.7/site-packages/werkzeug/__init__.py)

Add werkzeug == 0.16.1 to requirements.txt solved it for me.

Would someone mind providing some insight into why my flask request object returned from werkzeug's LocalProxy is from a different version then what I have locally?

Since this release I'm getting this error:
File "/Users/lucas/Software/anaconda3/envs/pytest/lib/python3.6/site-packages/flask/json.py", line 251, in jsonify if current_app.config['JSONIFY_PRETTYPRINT_REGULAR'] and not request.is_xhr: File "/Users/lucas/Software/anaconda3/envs/pytest/lib/python3.6/site-packages/werkzeug/local.py", line 347, in __getattr__ return getattr(self._get_current_object(), name) AttributeError: 'Request' object has no attribute 'is_xhr'

is_xhr is a property that was removed in Flask 1.0, but locally I have 0.12.2 installed. Just to be clear, I'm posting this issue here because the bug is not in Flask, rather I'm just confused as to why/how LocalProxy is returning a newer version of this Flask app then I'm expecting.

@LucasLLC is_xhr was never directly part of Flask (is there a reference that states it was removed in Flask 1.0? I can't see it in the changelog) rather it has always been a Werkzeug API that Flask exposes. In terms of Werkzeug you can see it is removed in 81e10efbf3a83daf09c55cd7cc13ac6c6464d405.

If you aren't already I'd recommend pinning your dependencies and periodically upgrading, a chore that is made easy by tools such as poetry.

@pgjones ideally we do a bugfix release of flask 0.12 which pins werkzeug to < 1.0.0. This is afterall a bad pin in Flask.

Also yes, this API is effectively Flask API and it was documented as such: https://flask.palletsprojects.com/en/0.12.x/api/#flask.Request.is_xhr

@LucasLLC is_xhr was never directly part of Flask (is there a reference that states it was removed in Flask 1.0? I can't see it in the changelog) rather it has always been a Werkzeug API that Flask exposes. In terms of Werkzeug you can see it is removed in 81e10ef.

Ah, my mistake. I was referencing the warning generated in this method, and didn't realize it was coming from Werkzeug, that makes a lot more sense.

If you aren't already I'd recommend pinning your dependencies and periodically upgrading, a chore that is made easy by tools such as poetry.

Thanks for the tip! We'll look into poetry.

Had issue while installing odoo12:

    import werkzeug.contrib.fixers
ImportError: No module named 'werkzeug.contrib'

However, resolved it with

Werkzeug==0.16.1

the same error happened

ModuleNotFoundError: No module named 'werkzeug.contrib'

Having the same issue with flask

Setting Werkzeug==0.16.1 fixed the issue.

```
from flask_admin.contrib.sqla import ModelView
File "/usr/local/lib/python3.6/site-packages/flask_admin/contrib/sqla/__init__.py", line 2, in

from .view import ModelView
File "/usr/local/lib/python3.6/site-packages/flask_admin/contrib/sqla/view.py", line 18, in

from flask_admin.model import BaseModelView
File "/usr/local/lib/python3.6/site-packages/flask_admin/model/__init__.py", line 2, in

from .base import BaseModelView
File "/usr/local/lib/python3.6/site-packages/flask_admin/model/base.py", line 8, in

from werkzeug import secure_filename
ImportError: cannot import name 'secure_filename'

Was this page helpful?
0 / 5 - 0 ratings

Related issues

asottile picture asottile  ·  11Comments

lepture picture lepture  ·  6Comments

alexgurrola picture alexgurrola  ·  5Comments

abathur picture abathur  ·  13Comments

androiddrew picture androiddrew  ·  14Comments