cocoindex-io/cocoindex · error · TypeError
mount() requires a ComponentSubpath when the function has no
Error message
mount() requires a ComponentSubpath when the function has no __name__. Provide an explicit subpath as the first argument.
What it means
mount() runs a function as a child processing component. It derives the component subpath from the function's __name__, which must be stable across runs for change detection and cleanup. Anonymous callables (lambdas, partials) have no __name__, so mount() requires an explicit ComponentSubpath.
Source
Thrown at python/cocoindex/_internal/api.py:390
Example:
await coco.mount(process_file, file, target)
# With explicit subpath:
await coco.mount(coco.component_subpath("process", filename), process_file, file, target)
"""
check_cancellation()
check_not_in_process_live("coco.mount")
if pos_args and isinstance(pos_args[0], ComponentSubpath):
subpath = pos_args[0]
processor_fn = pos_args[1]
args = pos_args[2:]
else:
processor_fn = pos_args[0]
args = pos_args[1:]
name = _default_subpath_name(processor_fn)
if name is None:
raise TypeError(
"mount() requires a ComponentSubpath when the function has no "
"__name__. Provide an explicit subpath as the first argument."
)
subpath = ComponentSubpath(Symbol(name))
parent_ctx = get_context_from_ctx()
child_path = build_child_path(parent_ctx, subpath)
if is_live_component_class(processor_fn):
instance = processor_fn(*args, **kwargs)
return await _mount_live_component(parent_ctx, child_path, instance)
processor = create_core_component_processor(
processor_fn, parent_ctx._env, child_path, args, kwargs
)
resolved = parent_ctx.resolve_exception_handler(
stable_path=child_path.to_string(),
processor_name=getattr(processor_fn, "__qualname__", None),View on GitHub (pinned to e84aa99b32)
Solutions
- Pass an explicit subpath first: coco.mount(coco.component_subpath('step'), fn, *args)
- Define a named function (def) instead of the anonymous callable
- Add @functools.wraps to custom decorators so wrapped functions keep __name__
Example fix
// before
await coco.mount(lambda f, t: t.declare_file(f.name, await f.read_text()), f, target)
// after
await coco.mount(coco.component_subpath("copy-file"), copy_file, f, target) Defensive patterns
Strategy: validation
Validate before calling
subpath = coco.component_subpath("step") if getattr(fn, "__name__", "<lambda>") == "<lambda>" else None
await coco.mount(subpath, fn, *args) if subpath else await coco.mount(fn, *args) Type guard
def mountable(fn) -> bool:
return callable(fn) and bool(getattr(fn, "__name__", "")) Try / catch
try:
await coco.mount(fn, *args)
except TypeError as e:
if "requires a ComponentSubpath" in str(e):
await coco.mount(coco.component_subpath("step"), fn, *args) Prevention
- Always mount named functions; never inline lambdas into mount()
- Set explicit subpaths for factory-produced or dynamically generated callables
When it happens
Trigger: Calling coco.mount(lambda ...: ..., ...) or coco.mount(functools.partial(fn), ...) with no explicit ComponentSubpath as the first argument.
Common situations: Inline lambdas in pipelines; decorated functions losing __name__ (missing functools.wraps); factory-produced closures.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- use_mount() requires a ComponentSubpath when the function ha
- mount_each() requires a ComponentSubpath when the function h
- LiveComponent classes cannot be used with use_mount(). Use m
- Cannot use sync 'with coco.runtime()' from within an async e
- coco.use_state() cannot be called inside a `with coco.compon
AI-assisted analysis of cocoindex-io/cocoindex@e84aa99b32 (2026-09-08).
Data as JSON: /api/errors/ce7c28de3d9cc233.
Report an issue: GitHub.