The Fix
Upgrade to version 2.1.3 or later.
Based on closed pallets/flask issue #3263 · 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%.
@@ -25,6 +25,9 @@ Unreleased
subclass sets this to ``False``, the view will not create a new
instance on every request. :issue:`2520`.
+- A ``flask.cli.FlaskGroup`` Click group can be nested as a
+ sub-command in a custom CLI. :issue:`3263`
+
# flask app sub group
@my_big_cli_group.group(cls=FlaskGroup, create_app=create_app)
@click.pass_context
def my_flask_app(ctx):
pass
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.1.3 or later.\nWhen NOT to use: This fix should not be used if the application relies on the original FlaskGroup behavior.\n\nOption C — Workaround\nfor this to be allowed? I guess at the end `Flask` should be fully compatible with all `click` functionalities (group `nesting` being one of the main ones).\nWhen NOT to use: This fix should not be used if the application relies on the original FlaskGroup behavior.\n\n
Why This Fix Works in Production
- Trigger: rv.update(info.load_app().cli.list_commands(ctx))
- Mechanism: FlaskGroup's main function is not called when nested in another click group
- Why the fix works: `FlaskGroup` can now be nested as a sub-command in a custom CLI, resolving the issue with `create_app` not being passed. (first fixed release: 2.1.3).
- 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
- Shows up under Python 3.7 in real deployments (not just unit tests).
- FlaskGroup's main function is not called when nested in another click group
- Surfaces as: Traceback (most recent call last):
Proof / Evidence
- GitHub issue: #3263
- Fix PR: https://github.com/pallets/flask/pull/4642
- First fixed release: 2.1.3
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.95
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.57
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“There are some bootstrap code in FlaskGroup.main(), so I think it is not allowed to nest it in another group, because the function is never…”
“Ah, interesting. Could there be any workaround for this to be allowed? I guess at the end Flask should be fully compatible with all click…”
“Passing create_app as a parameter doesn't work in this case, but you can still use FLASK_APP environment variable to do the trick. Note that some…”
“@u8sand Thanks a lot for your research! For anyone else wondering how to avoid this issue, this is the code I used (simplified a bit):”
Failure Signature (Search String)
- rv.update(info.load_app().cli.list_commands(ctx))
Error Message
Stack trace
Error Message
-------------
Traceback (most recent call last):
File “/Users/the_user/Desktop/venv/lib/python3.7/site-packages/flask/cli.py”, line 540, in list_commands
rv.update(info.load_app().cli.list_commands(ctx))
File “/Users/the_user/Desktop/venv/lib/python3.7/site-packages/flask/cli.py”, line 393, in load_app
‘Could not locate a Flask application. You did not provide ’
flask.cli.NoAppException: 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
# flask app sub group
@my_big_cli_group.group(cls=FlaskGroup, create_app=create_app)
@click.pass_context
def my_flask_app(ctx):
pass
Environment
- Python: 3.7
What Broke
Running nested Flask commands results in a NoAppException error.
Why It Broke
FlaskGroup's main function is not called when nested in another click group
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
Upgrade to version 2.1.3 or later.
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Option C — Workaround Temporary workaround
for this to be allowed? I guess at the end `Flask` should be fully compatible with all `click` functionalities (group `nesting` being one of the main ones).
Use only if you cannot change versions today. Treat this as a stopgap and remove once upgraded.
Fix reference: https://github.com/pallets/flask/pull/4642
First fixed release: 2.1.3
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be used if the application relies on the original FlaskGroup behavior.
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.1.3 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.