{"record":{"id":"ce7c28de3d9cc233","repo":"cocoindex-io/cocoindex","slug":"mount-requires-a-componentsubpath-when-the-funct","errorCode":null,"errorMessage":"mount() requires a ComponentSubpath when the function has no __name__. Provide an explicit subpath as the first argument.","messagePattern":"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":390,"sourceCode":"    Example:\n        await coco.mount(process_file, file, target)\n\n        # With explicit subpath:\n        await coco.mount(coco.component_subpath(\"process\", filename), process_file, file, target)\n    \"\"\"\n    check_cancellation()\n    check_not_in_process_live(\"coco.mount\")\n\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                \"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    parent_ctx = get_context_from_ctx()\n    child_path = build_child_path(parent_ctx, subpath)\n\n    if is_live_component_class(processor_fn):\n        instance = processor_fn(*args, **kwargs)\n        return await _mount_live_component(parent_ctx, child_path, instance)\n\n    processor = create_core_component_processor(\n        processor_fn, parent_ctx._env, child_path, args, kwargs\n    )\n    resolved = parent_ctx.resolve_exception_handler(\n        stable_path=child_path.to_string(),\n        processor_name=getattr(processor_fn, \"__qualname__\", None),","sourceCodeStart":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/_internal/api.py#L372-L408","documentation":"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.","triggerScenarios":"Calling coco.mount(lambda ...: ..., ...) or coco.mount(functools.partial(fn), ...) with no explicit ComponentSubpath as the first argument.","commonSituations":"Inline lambdas in pipelines; decorated functions losing __name__ (missing functools.wraps); factory-produced closures.","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__"],"exampleFix":"// before\nawait coco.mount(lambda f, t: t.declare_file(f.name, await f.read_text()), f, target)\n// after\nawait coco.mount(coco.component_subpath(\"copy-file\"), copy_file, f, target)","handlingStrategy":"validation","validationCode":"subpath = coco.component_subpath(\"step\") if getattr(fn, \"__name__\", \"<lambda>\") == \"<lambda>\" else None\nawait coco.mount(subpath, fn, *args) if subpath else await coco.mount(fn, *args)","typeGuard":"def mountable(fn) -> bool:\n    return callable(fn) and bool(getattr(fn, \"__name__\", \"\"))","tryCatchPattern":"try:\n    await coco.mount(fn, *args)\nexcept TypeError as e:\n    if \"requires a ComponentSubpath\" in str(e):\n        await coco.mount(coco.component_subpath(\"step\"), fn, *args)","preventionTips":["Always mount named functions; never inline lambdas into mount()","Set explicit subpaths for factory-produced or dynamically generated callables"],"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"}