cocoindex-io/cocoindex · error · TypeError
use_mount() requires a ComponentSubpath when the function ha
Error message
use_mount() requires a ComponentSubpath when the function has no __name__. Provide an explicit subpath as the first argument.
What it means
use_mount() runs a function as a child processing component and returns its value directly. The component subpath is normally derived from the function's __name__; when the callable has no usable __name__ (e.g. a lambda, functools.partial, or other anonymous callable), CocoIndex cannot derive a stable path and refuses to guess, since stable component paths are how runs are matched across updates.
Source
Thrown at python/cocoindex/_internal/api.py:270
Example:
target = await coco.use_mount(declare_table_target, table_name)
# With explicit subpath:
target = await coco.use_mount(
coco.component_subpath("setup"), declare_table_target, table_name
)
"""
check_cancellation()
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(
"use_mount() requires a ComponentSubpath when the function has no "
"__name__. Provide an explicit subpath as the first argument."
)
subpath = ComponentSubpath(Symbol(name))
check_not_in_process_live("coco.use_mount")
if is_live_component_class(processor_fn):
raise TypeError(
"LiveComponent classes cannot be used with use_mount(). "
"Use mount() instead."
)
parent_ctx = get_context_from_ctx()
child_path = build_child_path(parent_ctx, subpath)
# One explicit value travels through core: capture once, pass to both
# the processor (ContextVar restore in the wrapper) and the engine call.
deadline_context = _deadline_for_engine()View on GitHub (pinned to e84aa99b32)
Solutions
- Pass an explicit ComponentSubpath as the first argument: coco.use_mount(coco.component_subpath('my-step'), fn, *args)
- Use a named function (def) instead of a lambda/partial so the subpath can be auto-derived
- Set fn.__name__ on the callable if it is safe and the name is meaningful
Example fix
// before
result = await coco.use_mount(lambda ctx: build(ctx), ctx)
// after
result = await coco.use_mount(coco.component_subpath("build"), build, ctx) Defensive patterns
Strategy: validation
Validate before calling
def has_name(fn):
return getattr(fn, "__name__", None) not in (None, "<lambda>")
if not has_name(fn):
fn = coco.component_subpath("my-step") # pass subpath explicitly Type guard
def is_named_fn(fn) -> bool:
return callable(fn) and getattr(fn, "__name__", "<lambda>") != "<lambda>" Prevention
- Avoid lambdas/partials as mounted functions; prefer named @coco.fn functions
- Add functools.wraps to all custom decorators
- Pass an explicit component_subpath whenever the callable may be anonymous
When it happens
Trigger: Calling coco.use_mount(lambda ...: ..., ...) or coco.use_mount(functools.partial(fn, x)) without passing an explicit ComponentSubpath as the first positional argument.
Common situations: Passing lambdas or partially-applied functions inline for quick one-off mounts; wrapping functions with decorators that strip __name__; dynamically generated callables.
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
- mount() requires a ComponentSubpath when the function has no
- 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/8ab682f9d4e57cb0.
Report an issue: GitHub.