The Fix
Upgrade to version 2.0.0 or later.
Based on closed pallets/flask issue #3561 · PR/commit linked
Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.
@@ -27,6 +27,9 @@ Unreleased
- When specifying a factory function with ``FLASK_APP``, keyword
argument can be passed. :issue:`3553`
+- When loading a ``.env`` or ``.flaskenv`` file on top level directory,
+ Flask will not change current work directory to the location of dotenv
+ files, in order to prevent potential confusion. :pr:`3560`
# app.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello, Flask!'
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Upgrade to fixed release\nUpgrade to version 2.0.0 or later.\nWhen NOT to use: Do not use if it changes public behavior or if the failure cannot be reproduced.\n\n
Why This Fix Works in Production
- Trigger: Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the…
- Mechanism: Prevent Flask from changing the current working directory when loading .env or .flaskenv files from the top-level directory, which caused NoAppException errors.
- Why the fix works: Prevent Flask from changing the current working directory when loading .env or .flaskenv files from the top-level directory, which caused NoAppException errors. (first fixed release: 2.0.0).
- If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.
Why This Breaks in Prod
- Surfaces as: Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.
Proof / Evidence
- GitHub issue: #3561
- Fix PR: https://github.com/pallets/flask/pull/3560
- First fixed release: 2.0.0
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.63
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Also reported in #3535, which I closed for a larger discussion in https://github.com/pallets/flask/issues/3108#issuecomment-608550814. I'm not opposed to it, would be good to hear from @jab.”
“Sorry for the delay and thank you for the ping, @davidism. Responded in https://github.com/pallets/flask/pull/3560#issuecomment-612948226.”
Failure Signature (Search String)
- Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.
Error Message
Stack trace
Error Message
-------------
Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.
Minimal Reproduction
# app.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello, Flask!'
What Broke
Executing 'flask run' results in NoAppException due to incorrect working directory.
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
Upgrade to version 2.0.0 or later.
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Fix reference: https://github.com/pallets/flask/pull/3560
First fixed release: 2.0.0
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not use if it changes public behavior or if the failure cannot be reproduced.
Verify Fix
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Did This Fix Work in Your Case?
Quick signal helps us prioritize which fixes to verify and improve.
Prevention
- Capture the exact failing error string in logs and tests so you can reproduce via a minimal script.
- Pin production dependencies and upgrade only with a reproducible test that hits the failing path.
Version Compatibility Table
| Version | Status |
|---|---|
| 2.0.0 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.