{"record":{"id":"0ff24bcf19a62847","repo":"OpenBB-finance/OpenBB","slug":"error-the-name-instance-in-app-path-appears","errorCode":null,"errorMessage":"Error: The {name} instance in '{app_path}' appears not to be a callable factory function","messagePattern":"Error: The (.+?) instance in '(.+?)' appears not to be a callable factory function","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"openbb_platform/extensions/mcp_server/openbb_mcp_server/utils/app_import.py","lineNumber":92,"sourceCode":"        raise AttributeError(\n            f\"Error: The app file '{app_path}' does not contain an '{name}' instance\"\n        )\n\n    app_or_factory = getattr(module, name)\n\n    # Here we use the same approach as uvicorn to handle factory functions.\n    # This prevents us from relying on explicit type annotations.\n    # See: https://github.com/encode/uvicorn/blob/master/uvicorn/config.py\n    try:\n        app = app_or_factory()\n        if not factory:\n            print(  # noqa: T201\n                \"\\n\\n[WARNING]   \"\n                \"App factory detected. Using it, but please consider setting the --factory flag explicitly.\\n\"\n            )\n    except TypeError:\n        if factory:\n            raise TypeError(  # pylint: disable=raise-missing-from\n                f\"Error: The {name} instance in '{app_path}' appears not to be a callable factory function\"\n            )\n        app = app_or_factory\n\n    if not isinstance(app, FastAPI):\n        raise TypeError(\n            f\"Error: The {name} instance in '{app_path}' is not an instance of FastAPI\"\n        )\n\n    return app\n\n\ncl_doc = \"\"\"OpenBB MCP Server\n\nUsage:\n    >>> python -m openbb_mcp_server [OPTIONS]\n\n    >>> openbb-mcp --app ./some_app.py --host 0.0.0.0 --port 8005","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/extensions/mcp_server/openbb_mcp_server/utils/app_import.py#L74-L110","documentation":"TypeError raised when the --factory flag is set, the named attribute was found, but calling it raised TypeError — which the importer interprets as 'this attribute is not a callable factory function' (or its signature is not zero-argument callable). The same try/except otherwise silently tolerates calling a non-factory app instance.","triggerScenarios":"--app main.py:create_app --factory where create_app actually requires arguments (create_app(settings)); or the attribute is a plain FastAPI instance (not callable) while --factory was passed; or a factory with a typo'd required parameter.","commonSituations":"Copy-pasting a --factory command line against code whose factory needs configuration objects, flagging --factory 'just in case' when the target is already an instance, refactoring a factory to take arguments after the launch script was written.","solutions":["If the target is already a FastAPI instance, drop --factory","If it is a real factory, make it zero-argument callable (read its config from environment/settings inside the function)","Ensure --name points at the function itself, not at something it returns or wraps"],"exampleFix":"# before\ndef create_app(settings: Settings) -> FastAPI: ...\nopenbb-mcp --app main.py:create_app --factory\n\n# after\ndef create_app() -> FastAPI:\n    settings = Settings()\n    ...\nopenbb-mcp --app main.py:create_app --factory","handlingStrategy":"type-guard","validationCode":"import inspect\n\ntarget = getattr(module, name)\nif factory:\n    if not callable(target):\n        raise ValueError(f\"--factory set but {name!r} is not callable\")\n    try:\n        inspect.signature(target).bind()\n    except TypeError:\n        raise ValueError(f\"factory {name!r} must be callable with zero arguments\")","typeGuard":"def is_zero_arg_factory(module, name: str) -> bool:\n    import inspect\n    target = getattr(module, name, None)\n    if not callable(target):\n        return False\n    try:\n        inspect.signature(target).bind()\n        return True\n    except TypeError:\n        return False","tryCatchPattern":"try:\n    app = import_app(\"./main.py\", \"create_app\", True)\nexcept TypeError as e:\n    if \"not to be a callable factory\" in str(e):\n        app = import_app(\"./main.py\", \"create_app\", False)  # it is an instance\n    else:\n        raise","preventionTips":["Only pass --factory when the attribute is truly a zero-argument function","Keep factory functions parameterless; read config from env/settings inside","Test the exact CLI invocation in CI so factory/name drift is caught early"],"tags":["python","cli","factory","fastapi","callable"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}