{"record":{"id":"002a200af91db339","repo":"OpenBB-finance/OpenBB","slug":"error-the-name-instance-in-app-path-appears-002a20","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/platform_api/openbb_platform_api/utils/api.py","lineNumber":295,"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    app.add_middleware(\n        CORSMiddleware,\n        allow_origins=system.api_settings.cors.allow_origins,\n        allow_methods=system.api_settings.cors.allow_methods,\n        allow_headers=system.api_settings.cors.allow_headers,\n    )\n\n    AppLoader.add_exception_handlers(app)\n","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/extensions/platform_api/openbb_platform_api/utils/api.py#L277-L313","documentation":"Raised when --factory was passed and the named attribute was called as app_or_factory() but the call raised TypeError, meaning the attribute is not a zero-argument callable factory function (mirroring uvicorn's config logic).","triggerScenarios":"Running with factory=True where the named attribute is a FastAPI instance (not callable) or a function requiring arguments; calling an object whose __call__ signature needs parameters.","commonSituations":"Copy-pasting a factory-style command against a module that exports a plain app instance; a create_app(settings) factory that requires an argument; renaming between instance and factory styles.","solutions":["Drop the --factory flag if the module exposes a ready FastAPI instance.","If a factory is intended, make it zero-argument (wrap configuration inside it) and keep the flag.","Pass the correct --name pointing at the factory function (e.g. 'main:create_app').","Inspect the TypeError chained from the failed call for signature details."],"exampleFix":"# before\n# main.py: app = FastAPI()\nimport_app('main.py', 'app', factory=True)  # TypeError\n\n# after\nimport_app('main.py', 'app', factory=False)","handlingStrategy":"validation","validationCode":"obj = getattr(module, name)\nif factory:\n    assert callable(obj) and not isinstance(obj, FastAPI), \"--factory requires a zero-arg factory function\"","typeGuard":"def is_zero_arg_factory(obj) -> bool:\n    import inspect\n    return callable(obj) and not inspect.signature(obj).parameters.keys() and not isinstance(obj, FastAPI)","tryCatchPattern":"try:\n    app = import_app(path, name, factory=True)\nexcept TypeError as e:\n    if \"callable factory\" in str(e):\n        app = import_app(path, name, factory=False)  # attribute is an instance, not a factory\n    else:\n        raise","preventionTips":["Match --factory flag to the export style (function vs instance)","Make factories zero-argument","Standardize one pattern across services"],"tags":["fastapi","factory","startup","callable"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}