{"record":{"id":"9f50f3f7c7851265","repo":"pathwaycom/pathway","slug":"table-getitem-argument-has-to-be-a-columnrefer","errorCode":null,"errorMessage":"Table.__getitem__ argument has to be a ColumnReference to the same table or pw.this, or a string (or a list of those).","messagePattern":"Table\\.__getitem__ argument has to be a ColumnReference to the same table or pw\\.this, or a string \\(or a list of those\\)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/table.py","lineNumber":255,"sourceCode":"        ... 10  | Alice | dog\n        ... 9   | Bob   | dog\n        ... 8   | Alice | cat\n        ... 7   | Bob   | dog\n        ... ''')\n        >>> t2 = t1[[\"age\", \"pet\"]]\n        >>> t2 = t1[[\"age\", t1.pet]]\n        >>> pw.debug.compute_and_print(t2, include_id=False)\n        age | pet\n        7   | dog\n        8   | cat\n        9   | dog\n        10  | dog\n        \"\"\"\n        if isinstance(args, expr.ColumnReference):\n            if (args.table is not self) and not isinstance(\n                args.table, thisclass.ThisMetaclass\n            ):\n                raise ValueError(\n                    \"Table.__getitem__ argument has to be a ColumnReference to the same table or pw.this, or a string \"\n                    + \"(or a list of those).\"\n                )\n            return self._get_colref_by_name(args.name, KeyError)\n        elif isinstance(args, str):\n            return self._get_colref_by_name(args, KeyError)\n        else:\n            return self.select(*[self[name] for name in args])\n\n    @staticmethod\n    def _get_universe_solver() -> UniverseSolver:\n        return G.universe_solver\n\n    @trace_user_frame\n    @staticmethod\n    @check_arg_types\n    def from_columns(\n        *args: expr.ColumnReference, **kwargs: expr.ColumnReference","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/table.py#L237-L273","documentation":"Table.__getitem__ accepts a ColumnReference, a string, or a list of those. If given a ColumnReference, it must point at this table (args.table is self) or be a pw.this-style reference (ThisMetaclass); otherwise ValueError. The guard prevents silently selecting a column that belongs to a different table, which would break universe tracking.","triggerScenarios":"t1[t2.col] where t2 is a different Table object (even one with an identically named column); passing a column reference captured from another table after refactor/rebinding; using a reference stored in a variable long after its table was transformed.","commonSituations":"Copy-pasting code where column refs come from mixed tables; passing t.other.col instead of t.col; interactive sessions where an old variable holds a stale reference.","solutions":["Reference the column on the correct table: t1['col'] or t1.col","If the column genuinely lives on another table, join the tables first, then select","Use strings in list selections (t[['a','b']]) when mixing sources is not intended"],"exampleFix":"# before\nsel = t1[t2.age]  # ValueError: reference belongs to t2\n\n# after\nsel = t1['age']  # or t1.age\n# or, if the data is on t2:\njoined = t1.join(t2, t1.id == t2.id)\nsel = joined.select(joined.age)","handlingStrategy":"type-guard","validationCode":"def ref_belongs_to(ref, table) -> bool:\n    return ref.table is table","typeGuard":"import pathway as pw\n\ndef is_same_table_ref(ref, table: pw.Table) -> bool:\n    return isinstance(ref, pw.ColumnReference) and ref.table is table","tryCatchPattern":null,"preventionTips":["Select columns via attribute access on the owning table","Join tables before mixing their columns in one expression"],"tags":["column-reference","api-misuse","pathway"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}