pathwaycom/pathway · error · ValueError
The column {column} doesn't belong to the target table {tabl
Error message
The column {column} doesn't belong to the target table {table} What it means
DataSink.check_sort_by_columns validates a sink's sort_by columns before writing: every ColumnReference in sort_by must belong to the exact Table being written (column._table is the table object). Columns coming from another table (e.g. the pre-join inputs, or an intermediate table) fail this identity check.
Source
Thrown at python/pathway/internals/datasink.py:28
from pathway.internals import api
from pathway.internals.expression import ColumnReference
if TYPE_CHECKING:
from pathway.internals.table import Table
class DataSink(ABC):
@property
def name(self) -> str:
return type(self).__qualname__.lower().removesuffix("datasink")
def check_sort_by_columns(self, table: Table):
sort_by = getattr(self, "sort_by", None)
if sort_by is None:
return
for column in sort_by:
if column._table != table:
raise ValueError(
f"The column {column} doesn't belong to the target table {table}"
)
@dataclass(frozen=True)
class GenericDataSink(DataSink):
datastorage: api.DataStorage
dataformat: api.DataFormat
datasink_name: str
unique_name: str | None
sort_by: Iterable[ColumnReference] | None = None
on_pipeline_finished: Callable | None = None
@property
def name(self) -> str:
return self.datasink_name
@propertyView on GitHub (pinned to fa2f74a464)
Solutions
- Re-derive the columns from the table being written: out = t.select(...); pw.io.csv.write(out, sort_by=[out.x, out.y]).
- Chain immediately: write the table whose attribute columns you use in sort_by in the same expression scope.
- Drop sort_by if ordering is not required.
Example fix
# before sorted_cols = [t.x, t.y] out = t.select(x=pw.this.x, y=pw.this.y) pw.io.csv.write(out, path, sort_by=sorted_cols) # cols belong to t, not out # after out = t.select(x=pw.this.x, y=pw.this.y) pw.io.csv.write(out, path, sort_by=[out.x, out.y])
Defensive patterns
Strategy: validation
Validate before calling
assert all(c._table is table_being_written for c in (sort_by or [])), 'sort_by columns must come from the exact table written'
Type guard
def sort_by_columns_valid(table, sort_by) -> bool:
return all(c._table is table for c in (sort_by or [])) Prevention
- Derive sort_by from the final table object right at the write call.
- Never reuse column refs captured before a select/join transformation.
When it happens
Trigger: Passing sort_by=[t_src.col] where t_src is not the table handed to pw.io.json.write / csv.write etc., typically after a select/rename/join so the saved table object is a new instance while sort_by still references the old table's columns.
Common situations: Reusing column references captured before a transformation: cols = [t.x, t.y]; out = t.select(...); pw.io.csv.write(out, ..., sort_by=cols). Join outputs where sort_by references an input table's column.
Related errors
- direction argument of join should be of type asof_join.Direc
- The behavior argument of join should be of type pathway.temp
- The interval argument of a join should be of a type pathway.
- Join received extra kwargs. You probably want to use TableLi
- Expected a ColumnReference, found a string. Did you mean thi
AI-assisted analysis of pathwaycom/pathway@fa2f74a464 (2026-08-15).
Data as JSON: /api/errors/4b46dba3951f1a01.
Report an issue: GitHub.