{"record":{"id":"c9b19e89f4672d53","repo":"deepset-ai/haystack","slug":"pre-init-hooks-do-not-support-components-with-vari","errorCode":null,"errorMessage":"Pre-init hooks do not support components with variadic positional args in their init method","messagePattern":"Pre-init hooks do not support components with variadic positional args in their init method","errorType":"exception","errorClass":"ComponentError","httpStatus":null,"severity":"error","filePath":"haystack/core/component/component.py","lineNumber":199,"sourceCode":"    # note: Protocol member Component.run expected settable variable, got read-only attribute\n\n    def run(self, *args: Any, **kwargs: Any) -> Mapping[str, Any]:  # noqa: D102\n        ...\n\n\nclass ComponentMeta(type):\n    @staticmethod\n    def _positional_to_kwargs(cls_type: type, args: tuple[Any, ...]) -> dict[str, Any]:\n        \"\"\"\n        Convert positional arguments to keyword arguments based on the signature of the `__init__` method.\n        \"\"\"\n        init_signature = inspect.signature(cls_type.__init__)  # type:ignore[misc]\n        init_params = {name: info for name, info in init_signature.parameters.items() if name != \"self\"}\n\n        out = {}\n        for arg, (name, info) in zip(args, init_params.items(), strict=False):\n            if info.kind == inspect.Parameter.VAR_POSITIONAL:\n                raise ComponentError(\n                    \"Pre-init hooks do not support components with variadic positional args in their init method\"\n                )\n\n            assert info.kind in (inspect.Parameter.POSITIONAL_OR_KEYWORD, inspect.Parameter.POSITIONAL_ONLY)\n            out[name] = arg\n        return out\n\n    @staticmethod\n    def _parse_and_set_output_sockets(instance: Any) -> None:\n        has_async_run = hasattr(instance, \"run_async\")\n\n        # If `component.set_output_types()` was called in the component constructor,\n        # `__haystack_output__` is already populated, no need to do anything.\n        if not hasattr(instance, \"__haystack_output__\"):\n            # If that's not the case, we need to populate `__haystack_output__`\n            #\n            # If either of the run methods were decorated, they'll have a field assigned that\n            # stores the output specification. If both run methods were decorated, we ensure that","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/core/component/component.py#L181-L217","documentation":"Haystack's pre-init hooks (wiring the __init__ positional args into kwargs before a component is fully registered) map positional args to __init__ parameters by position. If __init__ declares *args (VAR_POSITIONAL), the mapping is impossible, so a ComponentError is raised. The library requires component __init__ signatures to be enumerable as named parameters.","triggerScenarios":"Instantiating a @component class whose __init__ contains *args positional variadic parameters, so ComponentMeta's pre-init hook (invoked on __init__ before the run method is set) cannot convert positional args to kwargs.","commonSituations":"Wrapping a third-party client class with variadic __init__ (e.g. def __init__(self, *args, **kwargs)) and decorating it with @component; forwarding args to an underlying SDK constructor.","solutions":["Rewrite __init__ to declare explicit named parameters instead of *args, forwarding them explicitly.","Collect extras as keyword-only via **kwargs instead of *args — only positional variadic args are rejected.","Instantiate the component without positional arguments (pass everything by keyword) — the hook still inspects the signature, so fixing the signature is the real fix.","If the class cannot be changed, wrap it in an adapter component with a named-parameter __init__."],"exampleFix":"// before\nclass MyComponent:\n    @component\n    def __init__(self, *args):\n        ...\n// after\nclass MyComponent:\n    @component\n    def __init__(self, api_key: str, model: str):\n        ...","handlingStrategy":"validation","validationCode":"import inspect\nparams = inspect.signature(MyComponent.__init__).parameters\nif any(p.kind == inspect.Parameter.VAR_POSITIONAL for p in params.values()):\n    raise TypeError(\"@component __init__ must not declare *args\")","typeGuard":"def has_named_init(cls: type) -> bool:\n    return not any(\n        p.kind == inspect.Parameter.VAR_POSITIONAL\n        for p in inspect.signature(cls.__init__).parameters.values()\n    )","tryCatchPattern":"try:\n    comp = MyComponent(\"key\", \"model\")\nexcept ComponentError as e:\n    if \"variadic positional args\" in str(e):\n        comp = MyComponent(api_key=\"key\", model=\"model\")","preventionTips":["Declare explicit named params in @component __init__","Use **kwargs, never *args, when forwarding extra options","Run unit tests that instantiate every component before pipeline use"],"tags":["haystack","component","init-signature","componenterror"],"backgroundTag":"unsupported-init-signature","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}