marshmallow-code / flask-smorest

DB agnostic framework to build auto-documented REST APIs with Flask and marshmallow
https://flask-smorest.readthedocs.io
MIT License
651 stars 72 forks source link

ImportError: cannot import name '_app_ctx_stack' from 'flask' #560

Closed kanavphull closed 11 months ago

kanavphull commented 11 months ago

I tried to import and use abort() function from the flask-smorest library, it gave me an error message as below:

Error: While importing 'app', an ImportError was raised:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/flask/cli.py", line 219, in locate_app
    __import__(module_name)
  File "/app/app.py", line 4, in <module>
    from flask_smorest import abort
  File "/usr/local/lib/python3.10/site-packages/flask_smorest/__init__.py", line 5, in <module>
    from .spec import APISpecMixin
  File "/usr/local/lib/python3.10/site-packages/flask_smorest/spec/__init__.py", line 12, in <module>
    from flask_smorest.utils import prepare_response
  File "/usr/local/lib/python3.10/site-packages/flask_smorest/utils.py", line 6, in <module>
    from flask import _app_ctx_stack
ImportError: cannot import name '_app_ctx_stack' from 'flask' (/usr/local/lib/python3.10/site-packages/flask/__init__.py)

Apparently, There seems to be a breaking change in 2.2.0, which should be considered in flask-smorest. Using downgraded version of flask i.e. 2.1.3 fixed this issue.

lafrech commented 11 months ago

Looks like you're using a version of flask-smorest that is older than 0.39.0 (2022-08-16).

kanavphull commented 11 months ago

I am actually using flask-smorest version: 0.42.1 and python version: 3.11.1

lafrech commented 11 months ago

Please double-check. We don't use _app_ctx_stack anymore (see CHANGELOG).

kanavphull commented 11 months ago

Right, Just noticed that the latest version does not use '_app_ctx_stack' Problem persists only with flask-smorest version 0.42.1 Thanks