jarus / flask-testing

Unittest extensions for Flask
http://pythonhosted.org/Flask-Testing/
Other
502 stars 111 forks source link

cannot import name 'cached_property' from 'werkzeug' #143

Open bill-uncultured opened 4 years ago

bill-uncultured commented 4 years ago

werkzeug just released 1.0.0, and the deprecated werkzeug.cached_property has been removed in favor of werkzeug.utils.cached_property.

This was addressed in October by pull request # 141, but it seems like it failed testing because the old python 3.3 and 2.6 couldn't be downloaded.

/usr/lib/python3.7/site-packages/flask_testing/__init__.py:13: in <module>
    from .utils import TestCase, LiveServerTestCase
/usr/lib/python3.7/site-packages/flask_testing/utils.py:35: in <module>
    from werkzeug import cached_property
E   ImportError: cannot import name 'cached_property' from 'werkzeug' (/usr/lib/python3.7/site-packages/werkzeug/__init__.py)
teapow commented 4 years ago

Same issue as: https://github.com/noirbizarre/flask-restplus/issues/777

The proposed temporary solution is to pin Werkzeug==0.16.1 until a proper fix is put in place.

erodrig commented 4 years ago

I have created a fix for this https://github.com/jarus/flask-testing/pull/144

but CI infrastructure is not working

Downloading archive: https://storage.googleapis.com/travis-ci-language-archives/python/binaries/ubuntu/16.04/x86_64/python-2.6.tar.bz2 0.10s$ curl -sSf --retry 5 -o python-2.6.tar.bz2 ${archive_url} curl: (22) The requested URL returned error: 404 Not Found

Ri1a commented 4 years ago

Another fix would be to edit the flask_testing/utils.py on line 35: Use from werkzeug.utils import cached_property instead of from werkzeug import cached_property

There's already a (closed) MR: https://github.com/jarus/flask-testing/pull/146

And an open one: https://github.com/jarus/flask-testing/pull/145

Edit: https://github.com/jarus/flask-testing/pull/145 has been merged

elgohr commented 4 years ago

Any updates regarding CI?

Sispheor commented 4 years ago

As it is fixed. Could you release a new version? :)

Rahulrao0786 commented 4 years ago
from werkzeug import cached_property

ImportError: cannot import name 'cached_property' from 'werkzeug' (C:\Users\BABA\PycharmProjects\Automation\venv\lib\site-packages\werkzeug__init__.py)

I am getting this error message

Rahulrao0786 commented 4 years ago

from flask import Flask from flask_restplus import Api, Resource from werkzeug.utils import *

app = Flask(name) api = Api(app)

@api.route('/language') class Language: def get(self): return {'hey': 'there'}

if name == "main": app.run(debug=True)

vicmunoz commented 4 years ago

I've fixed this with: import werkzeug werkzeug.cached_property = werkzeug.utils.cached_property

KareenaR commented 4 years ago

I've fixed this with: import werkzeug werkzeug.cached_property = werkzeug.utils.cached_property

Thanks! This works.

jnozsc commented 4 years ago

fyi: this issue has been fixed in version 0.8.0

evertoncastro commented 4 years ago

Updating to Werkzeug==0.16.1 has fixed.

mumapada commented 4 years ago

Changed lib\site-packages\flask_restx\api.py", line 28, in from werkzeug import cached_property as below :

from werkzeug import cached_property

from werkzeug.utils import cached_property

felixminom commented 3 years ago

Still happening when upgrading to 1.0.1 version

philipperemy commented 3 years ago

Still happening as of today.

SidJain1412 commented 3 years ago

Still broken with werkzeug==1.0.1 as of 4th Sept 2020

Can be fixed by adding

import werkzeug
werkzeug.cached_property = werkzeug.utils.cached_property

before importing flask_restplus

ctwardy commented 3 years ago

Thanks @SidJain1412!

User-side workaround when not expecting to call werkzeug directly:

try:
    from flask_restplus import Resource, Api
except ImportError:
    import werkzeug
    werkzeug.cached_property = werkzeug.utils.cached_property
    from flask_restplus import Resource, Api
JosephHubbard commented 3 years ago

This is still an issue. My API backend still fails when using untampered Flask due to "cannot import name 'cached_property' from 'werkzeug'".

bharath-kumarn commented 3 years ago

This is still an issue.

ontology_1 | File "./get_title_details.py", line 1, in ontology_1 | from robobrowser import RoboBrowser ontology_1 | File "/usr/local/lib/python3.6/site-packages/robobrowser/init.py", line 3, in ontology_1 | from .browser import RoboBrowser ontology_1 | File "/usr/local/lib/python3.6/site-packages/robobrowser/browser.py", line 8, in ontology_1 | from werkzeug import cached_property ontology_1 | ImportError: cannot import name 'cached_property'

paulakeen commented 3 years ago

If I downgrade to Werkzeug==0.16.1 I get this other error: from werkzeug.local import ContextVar ImportError: cannot import name 'ContextVar' from 'werkzeug.local' (/home/paula/venvs/bidlab-venv/lib/python3.8/site-packages/werkzeug/local.py)

ritesh-hubbler commented 3 years ago

Werkzeug==2.0.1 Flask==2.0.1 flask-restplus==0.13.0

With this requirements, the issue is still there, I downgraded to Werkzeug == 1.16.1 and downgraded other dependencies too... so it worked, but it should be working with latest version too, so please release a new version with this fix.

rafael-andrade commented 3 years ago

Werkzeug==2.0.1 Flask==2.0.1 flask-restplus==0.13.0

With this requirements, the issue is still there, I downgraded to Werkzeug == 1.16.1 and downgraded other dependencies too... so it worked, but it should be working with latest version too, so please release a new version with this fix.

When I downgrade it says: flask 2.0.1 requires Werkzeug>=2.0, but you'll have werkzeug 0.16.1 which is incompatible.. Any suggestions?

ipam73 commented 3 years ago

+1 Any ideas on how to resolve this? Haven't been able to solve the issue with the responses above and downgrading is not an option due to flask 2.0.1 not being compatible.

Flask==2.0.1 Flask-RESTful==0.3.9 Flask-Testing==0.7.1 Werkzeug==2.0.1

Traceback:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/unittest/loader.py", line 434, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/local/lib/python3.7/unittest/loader.py", line 375, in _get_module_from_name
    __import__(name)
  File "/usr/src/app/project/tests/test_account_model.py", line 6, in <module>
    from project.tests.base import BaseTestCase
  File "/usr/src/app/project/tests/base.py", line 4, in <module>
    from flask_testing import TestCase
  File "/usr/local/lib/python3.7/site-packages/flask_testing/__init__.py", line 13, in <module>
    from .utils import TestCase, LiveServerTestCase
  File "/usr/local/lib/python3.7/site-packages/flask_testing/utils.py", line 35, 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)
toddman2 commented 2 years ago

If I downgrade to Werkzeug==0.16.1 I get this other error: from werkzeug.local import ContextVar ImportError: cannot import name 'ContextVar' from 'werkzeug.local' (/home/paula/venvs/bidlab-venv/lib/python3.8/site-packages/werkzeug/local.py)

100%. I can't believe this is still going on.

bharath-kumarn commented 2 years ago

Yes

On Tue, 13 Jul, 2021, 9:19 am toddman2, @.***> wrote:

If I downgrade to Werkzeug==0.16.1 I get this other error: from werkzeug.local import ContextVar ImportError: cannot import name 'ContextVar' from 'werkzeug.local' (/home/paula/venvs/bidlab-venv/lib/python3.8/site-packages/werkzeug/local.py)

100%. I can't believe this is still going on.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jarus/flask-testing/issues/143#issuecomment-878755563, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALR2PCSCNX3Y2TKMUKDSPDDTXOZWHANCNFSM4KRE6NPQ .

palmettobugz commented 2 years ago

Maybe related: Switch locals to be based on ContextVars #1778 https://github.com/pallets/werkzeug/pull/1778 pgjones commented on Mar 28, 2020 • ContextVar was introduced in Python 3.7 and is effectively the same as Local in Werkzeug (although a different API). They should work in Greenlet and threading contexts as before but also now in asyncio or other async/await contexts.

The storage attribute has been kept for backwards compatibility (even though it is a dunder it seems it is used, e.g. in tests).

The ident_func though must be deprecated as this is now handled by the ContextVar. This may cause some backwards incompatibility.

4vadim4 commented 2 years ago

Is there a solution to this problem? Because the first mention with Flask==2.0.1, flask-restplus==0.13.0, Werkzeug==2.0.1 was in June. This bug has yet to be resolved?

Ninthpool commented 2 years ago

The issue still persists as of today... temporary workaround:

try: 
    from flask_restplus import Api, Resource
except ImportError:
    import werkzeug, flask.scaffold
    werkzeug.cached_property = werkzeug.utils.cached_property
    flask.helpers._endpoint_from_view_func = flask.scaffold._endpoint_from_view_func
    from flask_restplus import Api, Resource
vikramadhav commented 2 years ago

Current requirements.txt

Flask==2.1.2
Flask-Assets==2.0
flask-restplus==0.13.0
Werkzeug==2.1.2

and applied work around as (Downgrade is not possible due to compatibility)

try: 
    from flask_restplus import Api, Resource,Namespace
except ImportError:
    import werkzeug, flask.scaffold
    werkzeug.cached_property = werkzeug.utils.cached_property
    flask.helpers._endpoint_from_view_func = flask.scaffold._endpoint_from_view_func
    from flask_restplus import Api, Resource,Namespace

from models.hello_world import helloWork

data_edits_namespce=Namespace('data_edits')

data_edits_namespce.add_model('HelloWorld',helloWork)

Now the exception is coming

from flask_restplus import Api, Resource,Namespace
venv/lib/python3.10/site-packages/flask_restplus/model.py", line 8, in <module> from collections import OrderedDict, MutableMapping
ImportError: cannot import name 'MutableMapping' from 'collections' (/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/collections/__init__.py)

Not sure what i am missing here , does any one else also faced same issue

felixminom commented 2 years ago

We all should be migrating to flask-restx which is a wrapper for this library and it's been actively maintained.

toddman2 commented 2 years ago

Clearly seems the owner is busy these days or no longer has an interest in fixing this. I'm cutting the guy some slack -- it's been a useful package so far. It would be appreciated if he could check in with us one way or another. Thanks for all your time you've put into so far.

fauber5 commented 1 year ago

"

0 370.1 ERROR: Cannot install -r requirements.txt (line 32) and Werkzeug==0.16.1 because these package versions have conflicting dependencies.

0 370.1

0 370.1 The conflict is caused by:

0 370.1 The user requested Werkzeug==0.16.1

0 370.1 flask 2.0.2 depends on Werkzeug>=2.0

The temporary solution isn't possible. "pin Werkzeug==0.16.1 until a proper fix is put in place."