{"record":{"id":"54b9347e7001505c","repo":"pathwaycom/pathway","slug":"duplicate-expression-value-given-for-name","errorCode":null,"errorMessage":"Duplicate expression value given for {name}","messagePattern":"Duplicate expression value given for (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/desugaring.py","lineNumber":304,"sourceCode":"            evaled_table = arg._eval_substitution(substitution)\n            new_kwargs.update(evaled_table)\n    return {\n        name: _desugar_this_arg(substitution, arg) for name, arg in new_kwargs.items()\n    }\n\n\ndef combine_args_kwargs(\n    args: Iterable[expr.ColumnReference],\n    kwargs: Mapping[str, Any],\n    exclude_columns: set[str] | None = None,\n) -> dict[str, expr.ColumnExpression]:\n    all_args = {}\n\n    def add(name, expression):\n        if exclude_columns is not None and name in exclude_columns:\n            return\n        if name in all_args:\n            raise ValueError(f\"Duplicate expression value given for {name}\")\n        if name == \"id\":\n            raise ValueError(\"Can't use 'id' as a column name\")\n        if not isinstance(expression, expr.ColumnExpression):\n            expression = expr.ColumnConstExpression(expression)\n        all_args[name] = expression\n\n    for expression in args:\n        add(expr.smart_name(expression), expression)\n    for name, expression in kwargs.items():\n        add(name, expression)\n\n    return all_args\n\n\nclass DesugaringContext:\n    _substitution: dict[thisclass.ThisMetaclass, table.Joinable] = {}\n\n    @property","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/desugaring.py#L286-L322","documentation":"Pathway's select/with_columns-style APIs merge positional column references and keyword arguments into a single name->expression mapping. This ValueError is raised when two inputs resolve to the same output column name, because a column cannot be defined twice in one operation. The name for positional args comes from expr.smart_name(), so a positional column and a kwarg (or two columns from different tables with the same name) can silently collide.","triggerScenarios":"Calling table.select(t.a, a=t.b) or table.select(t1.a, t2.a) where smart_name of a positional reference equals a kwarg key or another positional's name; also select(*t1.columns, **{'a': t2.a}) patterns and with_columns variants that route through combine_args_kwargs.","commonSituations":"Renaming via kwargs while also passing the original column positionally; selecting same-named columns from two joined tables without renaming; copying a dict comprehension into kwargs that duplicates an existing column name; exclude_columns not covering the duplicate.","solutions":["Remove the duplicate: keep either the positional reference or the kwarg, not both, e.g. use select(a=t.b) to rename instead of passing both t.a and a=...","Rename colliding columns explicitly with kwarg syntax (select(left_value=t1.a, right_value=t2.a)) when selecting same-named columns from multiple tables","If building kwargs dynamically from a dict, filter out names already supplied positionally (or pass exclude_columns where the API supports it) before calling select"],"exampleFix":"// before\ntable.select(table.a, a=table.b)\n// after\ntable.select(a=table.b)","handlingStrategy":"validation","validationCode":"from pathway.internals import expression as expr\n\ndef safe_select_kwargs(args, kwargs):\n    names = [expr.smart_name(a) for a in args]\n    for name in kwargs:\n        if name in names:\n            raise ValueError(f\"duplicate column name '{name}' in select arguments\")\n    return kwargs","typeGuard":null,"tryCatchPattern":"try:\n    table.select(*args, **kwargs)\nexcept ValueError as e:\n    if \"Duplicate expression value given\" in str(e):\n        # dedupe names and retry with explicit renames\n        ...","preventionTips":["Never pass a column positionally and also as a kwarg with the same name","When selecting from joined tables, rename same-named columns explicitly","Build kwargs dynamically with a dict and check for collisions against positional names before the call"],"tags":["pathway","column-selection","duplicate-key","api-misuse"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}