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

Flask 2.0.0 - ImportError: cannot import name '_endpoint_from_view_func' from 'flask.helpers' #308

Closed
jloehel opened this issue May 11, 2021 · 17 comments · Fixed by #309
Closed
Labels
bug Something isn't working

Comments

@jloehel
Copy link
Contributor

jloehel commented May 11, 2021

The helper function is not longer available in Flask 2.0.0

flask-restful/flask-restful#913

@jloehel jloehel added the bug Something isn't working label May 11, 2021
@dendisuhubdy
Copy link

yes broke my pipeline

jloehel added a commit to jloehel/flask-restx that referenced this issue May 11, 2021
Changed in: pallets/flask@b146a13

Fixes: python-restx#308

Signed-off-by: Jürgen Löhel <juergen.loehel@inlyse.com>
@j5awry
Copy link
Contributor

j5awry commented May 11, 2021

Thanks for catching this quickly. I've told Github to run the tests. on the PR. I don't foresee any issues there. I'll get this merged into main, and then cut a release ASAP.

@jziem
Copy link

jziem commented May 12, 2021

flask-restful ran into same problem and fixed that issue: flask-restful/flask-restful#914

@cedricbonhomme
Copy link

Hello. Thank you for this fix. I did something similar in my venv. Are you going to publish the fix soonish on pypi ?

@cedricbonhomme
Copy link

Seems it is published on pypi, nice @j5awry . But there is a dependency issue with Flask 2.0, probably due to this:
https://github.com/python-restx/flask-restx/blob/master/requirements/install.pip#L4

$ poetry install
Creating virtualenv statsservice-eyi4DPj7-py3.9 in /home/cedric/.cache/pypoetry/virtualenvs
Updating dependencies
Resolving dependencies... (3.9s)

  SolverProblemError

  Because flask-restx (0.4.0) depends on Flask (>=0.8,<2.0.0)
   and no versions of flask-restx match >0.4.0,<0.5.0, flask_restx (>=0.4.0,<0.5.0) requires Flask (>=0.8,<2.0.0).
  So, because statsservice depends on both Flask (^2.0.0) and flask_restx (^0.4.0), version solving failed.

  at ~/.poetry/lib/poetry/puzzle/solver.py:241 in _solve
      237│             packages = result.packages
      238│         except OverrideNeeded as e:
      239│             return self.solve_in_compatibility_mode(e.overrides, use_latest=use_latest)
      240│         except SolveFailure as e:
    → 241│             raise SolverProblemError(e)
      242│ 
      243│         results = dict(
      244│             depth_first_search(
      245│                 PackageNode(self._package, packages), aggregate_package_nodes

@MoSehsah
Copy link

@cedricbonhomme I think sometimes this happens if you are using the same venv. Try to clear all packages from this venv and rerun pip again

@cedricbonhomme
Copy link

cedricbonhomme commented May 12, 2021

I deleted it, even cleaned the cache of poetry. Actually in the archive here it is written ''Flask>=0.8, <2.0.0''. So it seems poetry is right.

@j5awry
Copy link
Contributor

j5awry commented May 12, 2021

check your config.toml and pyproject.toml as well, or any place dependencies are being specified. statsservice (which i assume is your poetry proejct) is depending on Flask ^2.0.0 somewhere. So you should set in your dependencies explicitly to Flask < 2.0.0 or delete a pinned line somewhere. It's also possible that there's a pinned dependency file somewhere being generated by poetry for repeatability. you might need to grep around. < 2.0.0 would not require 2.0.0. It'd require anything less than. >= 2.0.0 would require 2.0.0

@cedricbonhomme
Copy link

cedricbonhomme commented May 12, 2021

In the pyproject.toml I have these lines:

Flask = "^2.0.0"
flask_restx = "^0.4.0"
...
...

To be sure I have deleted the lock file (poetry.lock). As well deleted the virtual env and cleaned the cache of poetry. I am not using a config.toml file.

What I do not understand it's this:
https://github.com/python-restx/flask-restx/blob/master/requirements/install.pip#L4
it seems it excludes verion 2.0.0 of Flask. Is this correct ?

On a new project:

cedric@numero5:~$ mkdir newproject
cedric@numero5:~$ cd newproject/
cedric@numero5:~/newproject$ poetry init   

This command will guide you through creating your pyproject.toml config.

Package name [newproject]:  
Version [0.1.0]:  
Description []:  
Author [Cédric Bonhomme <cedric@cedricbonhomme.org>, n to skip]:  
License []:  
Compatible Python versions [^3.9]:  

Would you like to define your main dependencies interactively? (yes/no) [yes] 
You can specify a package in the following forms:
  - A single name (requests)
  - A name and a constraint (requests@^2.23.0)
  - A git url (git+https://github.com/python-poetry/poetry.git)
  - A git url with a revision (git+https://github.com/python-poetry/poetry.git#develop)
  - A file path (../my-package/my-package.whl)
  - A directory (../my-package/)
  - A url (https://example.com/packages/my-package-0.1.0.tar.gz)

Search for package to add (or leave blank to continue): 

Would you like to define your development dependencies interactively? (yes/no) [yes] 
Search for package to add (or leave blank to continue): 

Generated file

[tool.poetry]
name = "newproject"
version = "0.1.0"
description = ""
authors = ["Cédric Bonhomme <cedric@cedricbonhomme.org>"]

[tool.poetry.dependencies]
python = "^3.9"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"


Do you confirm generation? (yes/no) [yes] 
cedric@numero5:~/newproject$ 
cedric@numero5:~/newproject$ 
cedric@numero5:~/newproject$ 
cedric@numero5:~/newproject$ ls -lh
total 4,0K
-rw-rw-r-- 1 cedric cedric 296 mai   12 17:10 pyproject.toml
cedric@numero5:~/newproject$ 
cedric@numero5:~/newproject$ 
cedric@numero5:~/newproject$ poetry install
Creating virtualenv newproject-Ur5O_nme-py3.9 in /home/cedric/.cache/pypoetry/virtualenvs
Updating dependencies
Resolving dependencies... (0.1s)

Writing lock file
cedric@numero5:~/newproject$ poetry add Flask
Using version ^2.0.0 for Flask

Updating dependencies
Resolving dependencies... (7.0s)

Writing lock file

Package operations: 6 installs, 0 updates, 0 removals

  • Installing markupsafe (2.0.0)
  • Installing click (8.0.0)
  • Installing itsdangerous (2.0.0)
  • Installing jinja2 (3.0.0)
  • Installing werkzeug (2.0.0)
  • Installing flask (2.0.0)
cedric@numero5:~/newproject$ poetry add flask_restx
Using version ^0.4.0 for flask-restx

Updating dependencies
Resolving dependencies... (0.1s)

  SolverProblemError

  Because no versions of flask-restx match >0.4.0,<0.5.0
   and flask-restx (0.4.0) depends on Flask (>=0.8,<2.0.0), flask-restx (>=0.4.0,<0.5.0) requires Flask (>=0.8,<2.0.0).
  So, because newproject depends on both Flask (^2.0.0) and flask-restx (^0.4.0), version solving failed.

  at ~/.poetry/lib/poetry/puzzle/solver.py:241 in _solve
      237│             packages = result.packages
      238│         except OverrideNeeded as e:
      239│             return self.solve_in_compatibility_mode(e.overrides, use_latest=use_latest)
      240│         except SolveFailure as e:
    → 241│             raise SolverProblemError(e)
      242│ 
      243│         results = dict(
      244│             depth_first_search(
      245│                 PackageNode(self._package, packages), aggregate_package_nodes

@frank2411
Copy link

I have the same problem as @cedricbonhomme. But directly with pip :)

@jloehel
Copy link
Contributor Author

jloehel commented May 12, 2021

it seems it excludes verion 2.0.0 of Flask. Is this correct ?

Yes, there are more steps to go. This isn't the only issue. For now it's better to use Flask 1.1.2 together with flask-restx. I am not so familiar with poetry but I think it should be:

Flask = "^1.1.2"

which is equal with:

>=1.1.2 <2.0.0

@cedricbonhomme
Copy link

cedricbonhomme commented May 12, 2021

exactly, that's the point (as you say).

But this release (v 0.4.0) of Flask-restx is supposed to work with Flask 2.0.

@j5awry
Copy link
Contributor

j5awry commented May 12, 2021

@cedricbonhomme No, it does not work with Flask 2.0.0. Hence the pin. There are other issues around Werkzeug and Flask that our CI pipeline tests found. We have pinned to < 2.0.0 for Flask and werkzeug until upstream bugs are addressed, and we can fix all calls in our code.

we fixed a single bug someone found, but the pipeline found more, some of which are upstream

@cedricbonhomme
Copy link

OK, thanks. Now I understand. My project actually works with Flask 2 and flask-restx 0.4.0 (i changed the lib in the venv manually). I will see if I can contribute to fix the errors I might have.

@jloehel
Copy link
Contributor Author

jloehel commented May 12, 2021

@cedricbonhomme You can install flask-restx also with --no-deps. I am not sure about the equivalent in poetry. It should be not necessary to patch it.

@j5awry
Copy link
Contributor

j5awry commented May 12, 2021

it's entirely possible that specific projects will work with Flask and werkzeug 2.0.0. Our tests are failing due to some specific tests. here's an example of a failure: https://github.com/python-restx/flask-restx/runs/2565726592

at least one is related to something report upstream to werkzeug: pallets/werkzeug#2115

we'll need to dig through a bit to see all possible interactions. I'll open a separate issue specifically to track upgrading flask and werkzeug to 2.0.0

@j5awry
Copy link
Contributor

j5awry commented May 12, 2021

#313 opened to track unpinning and fixing any other issues we find with upgrading flask and werkzeug

dev-jan added a commit to dev-jan/openEnergize that referenced this issue May 14, 2021
Since Poetry has better support for dependency management than using a
simple pip requirements file, Poetry is now used to fetch dependencies.
Also the versions are now more stricly given, since sometimes the most
up-to-date versions are not compatible with other up-to-date versions.

This happens with the new flask version 2.0.0, which came out this week
and break the build, since flask-restx is not working correctly with
flask 2.0.0

See python-restx/flask-restx#308
konstin pushed a commit to sacdallago/bio_embeddings that referenced this issue May 27, 2022
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.

7 participants