{"record":{"id":"8ab682f9d4e57cb0","repo":"cocoindex-io/cocoindex","slug":"use-mount-requires-a-componentsubpath-when-the-f","errorCode":null,"errorMessage":"use_mount() requires a ComponentSubpath when the function has no __name__. Provide an explicit subpath as the first argument.","messagePattern":"use_mount\\(\\) requires a ComponentSubpath when the function has no __name__\\. Provide an explicit subpath as the first argument\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/_internal/api.py","lineNumber":270,"sourceCode":"    Example:\n        target = await coco.use_mount(declare_table_target, table_name)\n\n        # With explicit subpath:\n        target = await coco.use_mount(\n            coco.component_subpath(\"setup\"), declare_table_target, table_name\n        )\n    \"\"\"\n    check_cancellation()\n    if pos_args and isinstance(pos_args[0], ComponentSubpath):\n        subpath = pos_args[0]\n        processor_fn = pos_args[1]\n        args = pos_args[2:]\n    else:\n        processor_fn = pos_args[0]\n        args = pos_args[1:]\n        name = _default_subpath_name(processor_fn)\n        if name is None:\n            raise TypeError(\n                \"use_mount() requires a ComponentSubpath when the function has no \"\n                \"__name__. Provide an explicit subpath as the first argument.\"\n            )\n        subpath = ComponentSubpath(Symbol(name))\n\n    check_not_in_process_live(\"coco.use_mount\")\n\n    if is_live_component_class(processor_fn):\n        raise TypeError(\n            \"LiveComponent classes cannot be used with use_mount(). \"\n            \"Use mount() instead.\"\n        )\n\n    parent_ctx = get_context_from_ctx()\n    child_path = build_child_path(parent_ctx, subpath)\n    # One explicit value travels through core: capture once, pass to both\n    # the processor (ContextVar restore in the wrapper) and the engine call.\n    deadline_context = _deadline_for_engine()","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/_internal/api.py#L252-L288","documentation":"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.","triggerScenarios":"Calling coco.use_mount(lambda ...: ..., ...) or coco.use_mount(functools.partial(fn, x)) without passing an explicit ComponentSubpath as the first positional argument.","commonSituations":"Passing lambdas or partially-applied functions inline for quick one-off mounts; wrapping functions with decorators that strip __name__; dynamically generated callables.","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"],"exampleFix":"// before\nresult = await coco.use_mount(lambda ctx: build(ctx), ctx)\n// after\nresult = await coco.use_mount(coco.component_subpath(\"build\"), build, ctx)","handlingStrategy":"validation","validationCode":"def has_name(fn):\n    return getattr(fn, \"__name__\", None) not in (None, \"<lambda>\")\n\nif not has_name(fn):\n    fn = coco.component_subpath(\"my-step\")  # pass subpath explicitly","typeGuard":"def is_named_fn(fn) -> bool:\n    return callable(fn) and getattr(fn, \"__name__\", \"<lambda>\") != \"<lambda>\"","tryCatchPattern":null,"preventionTips":["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"],"tags":["python","api-misuse","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b","analyzedAt":"2026-09-08T15:59:19.997Z","contentChangedAt":"2026-09-08T15:59:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}