Issue
I made some changes to my project (and after rebuilding its virtual environment) I started encountering this issue when running my suite of unit tests:
ImportError: cannot import name '_request_ctx_stack' from 'flask'
The weird thing is that I hadn't altered the code related to the tests that were failing nor had I changed the requirements of the project, which is why I was very confused
I tried undoing my changes (and rebuilding the virtual environment without my changes), but the error was still there, which was a signal that something else was happening
Solution
It wasn't until I asked for help from a teammate and he found that one of the packages that we were using in the newly created virtual environment had been automatically upgraded, namely Flask from 2.3.3 to 3.0.0.
Furthermore, he took a look at logs from the latest run that had worked and saw a deprecation warning message:
DeprecationWarning: '_request_ctx_stack' is deprecated and will be removed in Flask 2.4.
Therefore, the short-term fix was to change our requirements.txt file to set Flask 2.3.3 as the maximum version. It was previously flask>=1.1.4
.
However, the long-term fix will probably be to remove dependency of our project in flask-script package, since this package received its last update in 2017.
Answered By - alejandro
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.