pallets/flask · error · NoAppException

Detected factory '{attr_name}' in module '{module.__name__}'

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

A `NoAppException` from `find_best_app`: Flask's CLI found a factory function named `create_app` or `make_app` in the module and tried calling it with no arguments, but the call itself raised TypeError due to missing required parameters (verified via `_called_with_wrong_args` so genuine TypeErrors inside the factory are re-raised instead). Flask cannot invent the arguments, so it asks you to pass them in the app string.

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 6a2f545bfd)

Solutions

  1. Pass the arguments in the app string: `flask --app 'module:create_app("dev")' run` (arguments must be Python literals).
  2. Give the factory parameters default values (`def create_app(config_name='development')`) so a no-arg call works.
  3. Have the factory read configuration from environment variables instead of parameters.

Example fix

# before
def create_app(config_name):
    ...
# flask --app myapp run  -> Detected factory 'create_app' ... could not call it without arguments

# after (either)
flask --app 'myapp:create_app("production")' run
# or
def create_app(config_name="development"):
    ...
Defensive patterns

Strategy: validation

Validate before calling

import inspect
sig = inspect.signature(create_app)
callable_without_args = all(p.default is not inspect.Parameter.empty or p.kind in (inspect.Parameter.VAR_POSITIONAL, inspect.Parameter.VAR_KEYWORD) for p in sig.parameters.values())

Type guard

def factory_is_zero_arg(fn):
    import inspect
    return not any(p.default is inspect.Parameter.empty and p.kind is p.POSITIONAL_OR_KEYWORD for p in inspect.signature(fn).parameters.values())

Prevention

When it happens

Trigger: `flask --app module run` (or FLASK_APP=module) where the module defines `def create_app(config_name)` (or `make_app`) with one or more required positional parameters and no separate `app` instance exists.

Common situations: Application-factory projects whose factory requires a config name/object (`create_app('production')`); factories that grew a required parameter after initially working with `flask run`; tutorial code adapted to take an environment argument without updating FLASK_APP.

Related errors


AI-assisted analysis of pallets/flask@6a2f545bfd (2026-07-31). Data as JSON: /data/errors/0f141fde0a69a428.json. Report an issue: GitHub ↗.