{"record":{"id":"af722d5978effc15","repo":"cocoindex-io/cocoindex","slug":"mount-each-requires-a-componentsubpath-when-the","errorCode":null,"errorMessage":"mount_each() requires a ComponentSubpath when the function has no __name__. Provide an explicit subpath as the first argument.","messagePattern":"mount_each\\(\\) 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":484,"sourceCode":"\n    Returns:\n        A handle that can be used to wait until all processing units are ready.\n    \"\"\"\n    check_cancellation()\n    check_not_in_process_live(\"coco.mount_each\")\n\n    if pos_args and isinstance(pos_args[0], ComponentSubpath):\n        subpath = pos_args[0]\n        fn = pos_args[1]\n        items = pos_args[2]\n        extra_args = pos_args[3:]\n    else:\n        fn = pos_args[0]\n        items = pos_args[1]\n        extra_args = pos_args[2:]\n        name = _default_subpath_name(fn)\n        if name is None:\n            raise TypeError(\n                \"mount_each() 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 isinstance(items, LiveMapFeed):\n        # Live data source: the per-item `fn` (whether a plain function or a\n        # LiveComponent class) is dispatched through `mount()` / `operator.update()`\n        # inside `_MountEachLiveComponent`, both of which already handle live\n        # component classes — so no special-casing of `fn` is needed here.\n        instance = _MountEachLiveComponent(items, fn, extra_args, kwargs)\n        return await _mount_live_component(parent_ctx, child_path, instance)\n\n    # Static data source: mount one component per item. When `fn` is a\n    # LiveComponent class, each item gets its own live component instance","sourceCodeStart":466,"sourceCodeEnd":502,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/_internal/api.py#L466-L502","documentation":"mount_each() mounts the same function once per item and, like mount(), derives each component's subpath from the function's __name__ (composed with the item path). If the function is anonymous it cannot derive a stable subpath, so an explicit ComponentSubpath must be supplied.","triggerScenarios":"Calling coco.mount_each(lambda item: ..., items, ...) or with any callable lacking __name__, without an explicit ComponentSubpath as the first argument.","commonSituations":"Using lambdas in per-item loops; applying mount_each to partial-bound functions; custom decorators dropping __name__.","solutions":["Pass an explicit subpath: coco.mount_each(coco.component_subpath('process'), fn, items, *extra_args)","Use a named @coco.fn function as the per-item processor","Ensure decorators use functools.wraps to preserve __name__"],"exampleFix":"// before\nawait coco.mount_each(lambda f, t: process(f, t), files.items(), target)\n// after\nawait coco.mount_each(process_file, files.items(), target)","handlingStrategy":"validation","validationCode":"name = getattr(fn, \"__name__\", None)\nif name is None:\n    await coco.mount_each(coco.component_subpath(\"process-item\"), fn, items, *extra)\nelse:\n    await coco.mount_each(fn, items, *extra)","typeGuard":"def per_item_fn_ok(fn) -> bool:\n    return callable(fn) and getattr(fn, \"__name__\", \"<lambda>\") != \"<lambda>\"","tryCatchPattern":"try:\n    await coco.mount_each(fn, items, *extra)\nexcept TypeError as e:\n    if \"requires a ComponentSubpath\" in str(e):\n        await coco.mount_each(coco.component_subpath(\"process-item\"), fn, items, *extra)","preventionTips":["Use named @coco.fn functions for per-item processors","Don't wrap per-item processors in decorators lacking functools.wraps"],"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"}