{"record":{"id":"b0c02cb04628f3a5","repo":"pathwaycom/pathway","slug":"tableslice-method-arguments-should-refer-to-table","errorCode":null,"errorMessage":"TableSlice method arguments should refer to table of which the slice was created.","messagePattern":"TableSlice method arguments should refer to table of which the slice was created\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/table_slice.py","lineNumber":148,"sourceCode":"        return TableSlice(\n            {name: new_table[colref._name] for name, colref in self._mapping.items()},\n            new_table,\n        )\n\n    @property\n    def slice(self):\n        return self\n\n    def _normalize(self, arg: str | ColumnReference):\n        if isinstance(arg, ColumnReference):\n            if isinstance(arg.table, ThisMetaclass):\n                if arg.table != this:\n                    raise ValueError(\n                        f\"TableSlice expects {repr(arg.name)} or this.{arg.name} argument as column reference.\"\n                    )\n            else:\n                if arg.table != self._table:\n                    raise ValueError(\n                        \"TableSlice method arguments should refer to table of which the slice was created.\"\n                    )\n            return arg.name\n        else:\n            return arg\n","sourceCodeStart":130,"sourceCodeEnd":154,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/table_slice.py#L130-L154","documentation":"Raised by TableSlice._normalize() when a ColumnReference is bound to a Table object different from the table the slice was created from. Slice methods only accept references that belong to the slice's own table, which prevents silently mixing columns from unrelated tables.","triggerScenarios":"Passing table_b.col into a slice created from table_a (e.g. table_a.select('x').without(table_b.y)); passing references from a copy or a derived/reduced table object; mixing references after a join where the reference points at one of the input tables.","commonSituations":"Multi-table pipelines where similarly named columns exist on several tables; refactorings that swapped variable names so a slice and a reference no longer share the same Table instance; join results where columns must be referenced via the joined table.","solutions":["Pass plain strings for column names on the slice's own table: without('y') instead of table_b.y","Create the reference from the same table the slice came from: table_a.y, not table_b.y","After a join, use the join result's references (e.g. table_b['y'] on the joined table) or strings, matching the slice's origin"],"exampleFix":"# before\nslice = table_a.select(\"x\")\nslice.without(table_b.y)  # ValueError: reference belongs to another table\n\n# after\nslice.without(\"y\")\n# or, if the column is on table_a:\nslice.without(table_a.y)","handlingStrategy":"type-guard","validationCode":"def ref_belongs_to_table(ref, table) -> bool:\n    return getattr(ref, \"table\", None) is table\n\n# usage\nassert ref_belongs_to_table(table_b.y, table_a), \"reference from wrong table\"","typeGuard":"def ref_belongs_to_table(ref, table) -> bool:\n    return getattr(ref, \"table\", None) is table","tryCatchPattern":"try:\n    slice2 = table_slice.without(ref)\nexcept ValueError as e:\n    if \"should refer to table\" in str(e):\n        slice2 = table_slice.without(ref.name)\n    else:\n        raise","preventionTips":["Pass strings, not foreign ColumnReferences, to slice methods","Name variables after their table (orders_slice, users_slice) to avoid cross-table mixups","After joins, rebuild references from the join result table"],"tags":["pathway","table-slice","column-reference","wrong-table"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}