{"record":{"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/3596b1ab61cea85edb8970e83ff61daa073facf8/src/flask/cli.py#L62-L98","documentation":"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.","triggerScenarios":"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.","commonSituations":"Application factory that requires a config name or environment argument; refactored factory signature not yet reflected in FLASK_APP.","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."],"exampleFix":"// before\ndef create_app(config_name: str): ...\n# FLASK_APP=module -> raises\n// after\n# export FLASK_APP='module:create_app(\"production\")'\n# or give a default:\ndef create_app(config_name: str = 'development'): ...","handlingStrategy":"validation","validationCode":"import inspect\ndef factory_callable_no_args(f):\n    try:\n        inspect.signature(f).bind()\n        return True\n    except TypeError:\n        return False","typeGuard":"import inspect\ndef factory_takes_no_args(f) -> bool:\n    params = inspect.signature(f).parameters\n    return all(p.default is not p.empty for p in params.values())","tryCatchPattern":"try:\n    app = create_app()\nexcept TypeError:\n    # supply args via FLASK_APP='module:create_app(\"prod\")'\n    raise","preventionTips":["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."],"tags":["cli","factory","flask-app-env"],"backgroundTag":null,"analyzedSha":"3596b1ab61cea85edb8970e83ff61daa073facf8","analyzedAt":"2026-08-11T20:11:52.622Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}