{"id":"0f141fde0a69a428","repo":"pallets/flask","slug":"detected-factory-attr-name-in-module-module","errorCode":null,"errorMessage":"Detected factory '{attr_name}' in module '{module.__name__}', but could not call it without arguments. Use '{module.__name__}:{attr_name}(args)' to specify arguments.","messagePattern":"Detected factory '(.+?)' in module '(.+?)', but could not call it without arguments\\. Use '(.+?):(.+?)\\(args\\)' to specify arguments\\.","errorType":"exception","errorClass":"NoAppException","httpStatus":null,"severity":"error","filePath":"src/flask/cli.py","lineNumber":80,"sourceCode":"            f\" '{module.__name__}'. Use '{module.__name__}:name'\"\n            \" to specify the correct one.\"\n        )\n\n    # Search for app factory functions.\n    for attr_name in (\"create_app\", \"make_app\"):\n        app_factory = getattr(module, attr_name, None)\n\n        if inspect.isfunction(app_factory):\n            try:\n                app = app_factory()\n\n                if isinstance(app, Flask):\n                    return app\n            except TypeError as e:\n                if not _called_with_wrong_args(app_factory):\n                    raise\n\n                raise NoAppException(\n                    f\"Detected factory '{attr_name}' in module '{module.__name__}',\"\n                    \" but could not call it without arguments. Use\"\n                    f\" '{module.__name__}:{attr_name}(args)'\"\n                    \" to specify arguments.\"\n                ) from e\n\n    raise NoAppException(\n        \"Failed to find Flask application or factory in module\"\n        f\" '{module.__name__}'. Use '{module.__name__}:name'\"\n        \" to specify one.\"\n    )\n\n\ndef _called_with_wrong_args(f: t.Callable[..., Flask]) -> bool:\n    \"\"\"Check whether calling a function raised a ``TypeError`` because\n    the call failed or because something in the factory raised the\n    error.\n","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/pallets/flask/blob/6a2f545bfd8ed31e19066a299296917e034aca58/src/flask/cli.py#L62-L98","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","solutions":["Pass the arguments in the app string: `flask --app 'module:create_app(\"dev\")' run` (arguments must be Python literals).","Give the factory parameters default values (`def create_app(config_name='development')`) so a no-arg call works.","Have the factory read configuration from environment variables instead of parameters."],"exampleFix":"# before\ndef create_app(config_name):\n    ...\n# flask --app myapp run  -> Detected factory 'create_app' ... could not call it without arguments\n\n# after (either)\nflask --app 'myapp:create_app(\"production\")' run\n# or\ndef create_app(config_name=\"development\"):\n    ...","handlingStrategy":"validation","validationCode":"import inspect\nsig = inspect.signature(create_app)\ncallable_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())","typeGuard":"def factory_is_zero_arg(fn):\n    import inspect\n    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())","tryCatchPattern":null,"preventionTips":["Give create_app() default values for all parameters so the CLI can call it without arguments","When arguments are required, invoke as --app 'module:create_app(\"config-name\")' with literal args","Prefer environment variables over factory parameters for configuration so the zero-arg call works"],"tags":["flask","cli","app-factory","configuration"],"analyzedSha":"6a2f545bfd8ed31e19066a299296917e034aca58","analyzedAt":"2026-07-31T19:13:49.921Z","schemaVersion":2}