{"record":{"id":"305e3fa190724bd9","repo":"OpenBB-finance/OpenBB","slug":"error-the-name-instance-in-app-path-is-not-305e3f","errorCode":null,"errorMessage":"Error: The {name} instance in '{app_path}' is not an instance of FastAPI","messagePattern":"Error: The (.+?) instance in '(.+?)' is not an instance of FastAPI","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"openbb_platform/extensions/platform_api/openbb_platform_api/utils/api.py","lineNumber":301,"sourceCode":"    # 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\n    return app\n\n\ndef parse_args():  # noqa: PLR0912  # pylint: disable=too-many-branches\n    \"\"\"Parse the launch script command line arguments.\"\"\"\n    args = sys.argv[1:].copy()","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/extensions/platform_api/openbb_platform_api/utils/api.py#L283-L319","documentation":"Final type check in import_app: after retrieving (or calling) the named attribute, the resulting object is not an instance of fastapi.FastAPI, so it cannot be served or have CORS middleware attached.","triggerScenarios":"The module attribute named 'app' holds a Starlette/Flask/Django app, an APIRouter, a string, or any non-FastAPI object; or a factory returned something other than a FastAPI instance.","commonSituations":"Migrating a Starlette app and expecting the OpenBB loader to serve it; exposing an APIRouter under the name 'app'; a factory returning a tuple (app, lifespan) instead of the app.","solutions":["Ensure the named attribute is the FastAPI(...) instance itself.","If using a router, wrap it: app = FastAPI(); app.include_router(router).","If the factory returns extra objects, change it to return only the FastAPI app.","Verify with isinstance(module.app, FastAPI) in a quick REPL check."],"exampleFix":"# before\n# main.py\nrouter = APIRouter()\n\n# after\n# main.py\napp = FastAPI()\napp.include_router(router)","handlingStrategy":"type-guard","validationCode":"from fastapi import FastAPI\nobj = getattr(module, name)\nassert isinstance(obj, FastAPI), f\"expected FastAPI instance, got {type(obj).__name__}\"","typeGuard":"from fastapi import FastAPI\ndef is_fastapi_app(obj) -> bool:\n    return isinstance(obj, FastAPI)","tryCatchPattern":"try:\n    app = import_app(path, name)\nexcept TypeError as e:\n    if \"not an instance of FastAPI\" in str(e):\n        raise SystemExit(\"expose the FastAPI(...) instance as the named attribute\") from e\n    raise","preventionTips":["Expose the FastAPI app itself, not a router or foreign framework app","Return only the app from factories","Add an isinstance check in CI smoke tests"],"tags":["fastapi","type-check","startup"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}