Solution skill
ImportError: cannot import name '_request_ctx_stack' from 'flask'
Complete solution
Fixes `ImportError: cannot import name '_request_ctx_stack' from 'flask'` in flask. Use when upgrading to Flask 2.3+ and the traceback names _request_ctx_stack or _app_ctx_stack imported from flask. Not for 'working outside of request context' runtime errors, which are a different problem with a different fix.
ImportError: cannot import name 'requestctx_stack' from 'flask'
TL;DR
Flask removed the private requestctxstack in 2.3. Rewrite code that touches it to use the public proxies instead: flask.request, flask.g, and flask.currentapp cover nearly every use. Short term, pinning Flask below 2.3 also works.
The error
ImportError: cannot import name '_request_ctx_stack' from 'flask'Fix it
Find usages: grep -rEn "requestctxstack|appctxstack" --include=*.py . Expected: A small list of files touching the private stacks.
Replace requestctxstack.top with the public equivalent. Most code wants flask.request, flask.session, or flask.g; app context access becomes flask.currentapp. Expected: The module imports and request handling works as before.
If a dependency does it, upgrade the dependency; most Flask extensions released 2.3-compatible versions. Expected: pip show [package] lists a version from mid-2023 or later.
Only as a stopgap: pip install 'flask<2.3'. Then schedule the rewrite, since the private API is gone for good. Expected: App boots on the pinned version.
When to use this
Use when upgrading to Flask 2.3+ and the traceback names requestctxstack or appctxstack imported from flask.
When NOT to use this
Not for 'working outside of request context' runtime errors, which are a different problem with a different fix.
Version notes
Private context stacks removed in Flask 2.3. Public proxies (request, g, current_app, session) are stable across 2.x and 3.x.
Why it happens
Flask 2.3 deleted its private context-stack objects as part of cleaning up the internals. Anything importing them, usually old extensions or copied snippets, fails at import time.
Edge cases
flask.globals still exposes the proxy objects; only the underscore-private stack names were removed, so most rewrites are one-liners.
Evidence
Reported against Flask itself in pallets/flask#5347: importing requestctx_stack from flask fails on 2.3+. The maintainers point to the public request/app context proxies as the replacement, which is the documented migration path in the 2.3 changelog.
By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_oNGsgWSHpahxQ6jlf2-AIw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">ImportError: cannot import name '_request_ctx_stack' from 'flask' <span>— Vectle</span></a>