OpenBB-finance/OpenBB · error · TypeError
Error: The {name} instance in '{app_path}' appears not to be
Error message
Error: The {name} instance in '{app_path}' appears not to be a callable factory function What it means
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).
Source
Thrown at openbb_platform/extensions/platform_api/openbb_platform_api/utils/api.py:295
raise AttributeError(
f"Error: The app file '{app_path}' does not contain an '{name}' instance"
)
app_or_factory = getattr(module, name)
# Here we use the same approach as uvicorn to handle factory functions.
# This prevents us from relying on explicit type annotations.
# See: https://github.com/encode/uvicorn/blob/master/uvicorn/config.py
try:
app = app_or_factory()
if not factory:
print( # noqa: T201
"\n\n[WARNING] "
"App factory detected. Using it, but please consider setting the --factory flag explicitly.\n"
)
except TypeError:
if factory:
raise TypeError( # pylint: disable=raise-missing-from
f"Error: The {name} instance in '{app_path}' appears not to be a callable factory function"
)
app = app_or_factory
if not isinstance(app, FastAPI):
raise TypeError(
f"Error: The {name} instance in '{app_path}' is not an instance of FastAPI"
)
app.add_middleware(
CORSMiddleware,
allow_origins=system.api_settings.cors.allow_origins,
allow_methods=system.api_settings.cors.allow_methods,
allow_headers=system.api_settings.cors.allow_headers,
)
AppLoader.add_exception_handlers(app)
View on GitHub (pinned to 3e071fcc2c)
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.
Example fix
# before
# main.py: app = FastAPI()
import_app('main.py', 'app', factory=True) # TypeError
# after
import_app('main.py', 'app', factory=False) Defensive patterns
Strategy: validation
Validate before calling
obj = getattr(module, name)
if factory:
assert callable(obj) and not isinstance(obj, FastAPI), "--factory requires a zero-arg factory function" Type guard
def is_zero_arg_factory(obj) -> bool:
import inspect
return callable(obj) and not inspect.signature(obj).parameters.keys() and not isinstance(obj, FastAPI) Try / catch
try:
app = import_app(path, name, factory=True)
except TypeError as e:
if "callable factory" in str(e):
app = import_app(path, name, factory=False) # attribute is an instance, not a factory
else:
raise Prevention
- Match --factory flag to the export style (function vs instance)
- Make factories zero-argument
- Standardize one pattern across services
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Error: The {name} instance in '{app_path}' appears not to be
- Error: The {name} instance in '{app_path}' is not an instanc
- Failed to load the file specs for '{file_path}'
- Error: Neither module '{module_path}' could be imported nor
- Error: The app file '{app_path}' does not exist
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/002a200af91db339.
Report an issue: GitHub.