pallets/flask · error · NoAppException
Detected factory ' ' in module ' ', but could not call it…
Error message
Detected factory '{attr_name}' in module '{module.__name__}', but could not call it without arguments. Use '{module.__name__}:{attr_name}(args)' to specify arguments. What it means
Raised when Flask's CLI finds a factory function named create_app or make_app in the module but calling it with no arguments raises a TypeError attributable to a wrong call signature (not an internal error). The factory needs arguments the CLI cannot infer.
Solutions
- Pass arguments via FLASK_APP syntax: export FLASK_APP='module:create_app("production")'.
- Give the factory arguments defaults so it can be called with no args.
- Provide a no-arg wrapper or environment-driven factory.
Example fix
// before
def create_app(config_name: str): ...
# FLASK_APP=module -> raises
// after
# export FLASK_APP='module:create_app("production")'
# or give a default:
def create_app(config_name: str = 'development'): ... Defensive patterns
Strategy: validation
Validate before calling
import inspect
def factory_callable_no_args(f):
try:
inspect.signature(f).bind()
return True
except TypeError:
return False Type guard
import inspect
def factory_takes_no_args(f) -> bool:
params = inspect.signature(f).parameters
return all(p.default is not p.empty for p in params.values()) Try / catch
try:
app = create_app()
except TypeError:
# supply args via FLASK_APP='module:create_app("prod")'
raise Prevention
- Give factory args sensible defaults.
- Use FLASK_APP='module:create_app("production")' to pass literals.
- Wrap with a no-arg factory if args must come from env.
When it happens
Trigger: def create_app(config_name): ... declared in the module, FLASK_APP=module with no args supplied; the CLI calls create_app() and the missing positional arg triggers TypeError detected by _called_with_wrong_args.
Common situations: Application factory that requires a config name or environment argument; refactored factory signature not yet reflected in FLASK_APP.
Related errors
- Detected multiple Flask applications in module
- Failed to find attribute
- Failed to find Flask application or factory in module
- Failed to parse as an attribute name or function call.
- Failed to parse arguments as literal values
AI-assisted analysis of pallets/flask@3596b1ab61 (2026-08-11).
Data as JSON: /api/errors/0f141fde0a69a428.
Report an issue: GitHub.
Appendix: source
Thrown at src/flask/cli.py:80
f" '{module.__name__}'. Use '{module.__name__}:name'"
" to specify the correct one."
)
# Search for app factory functions.
for attr_name in ("create_app", "make_app"):
app_factory = getattr(module, attr_name, None)
if inspect.isfunction(app_factory):
try:
app = app_factory()
if isinstance(app, Flask):
return app
except TypeError as e:
if not _called_with_wrong_args(app_factory):
raise
raise NoAppException(
f"Detected factory '{attr_name}' in module '{module.__name__}',"
" but could not call it without arguments. Use"
f" '{module.__name__}:{attr_name}(args)'"
" to specify arguments."
) from e
raise NoAppException(
"Failed to find Flask application or factory in module"
f" '{module.__name__}'. Use '{module.__name__}:name'"
" to specify one."
)
def _called_with_wrong_args(f: t.Callable[..., Flask]) -> bool:
"""Check whether calling a function raised a ``TypeError`` because
the call failed or because something in the factory raised the
error.
View on GitHub (pinned to 3596b1ab61)