{"record":{"id":"dca5eec2a984633f","repo":"pathwaycom/pathway","slug":"type-annotation-of-column-column-name-does-not","errorCode":null,"errorMessage":"type annotation of column `{column_name}` does not match column definition","messagePattern":"type annotation of column `(.+?)` does not match column definition","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/schema.py","lineNumber":217,"sourceCode":"                fields[column_name] = column_schema.to_definition()\n\n    columns = {}\n\n    for column_name, annotation in annotations.items():\n        col_dtype = dt.wrap(annotation)\n        column = fields.pop(column_name, column_definition(dtype=col_dtype))\n\n        if not isinstance(column, ColumnDefinition):\n            raise ValueError(\n                f\"`{column_name}` should be a column definition, found {type(column)}\"\n            )\n\n        dtype = column.dtype\n        if dtype is None:\n            dtype = col_dtype\n\n        if col_dtype != dtype:\n            raise TypeError(\n                f\"type annotation of column `{column_name}` does not match column definition\"\n            )\n\n        column_name = column.name or column_name\n\n        def _get_column_property(property_name: str, default: Any) -> Any:\n            match (\n                getattr(column, property_name),\n                getattr(schema_properties, property_name),\n            ):\n                case (None, None):\n                    return default\n                case (None, schema_property):\n                    return schema_property\n                case (column_property, None):\n                    return column_property\n                case (column_property, schema_property):\n                    if column_property != schema_property:","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/schema.py#L199-L235","documentation":"A schema column's declared dtype comes from two places: the type annotation and (optionally) the dtype= inside column_definition. If both are given and disagree (after None-defaulting), schema building fails with this TypeError, because Pathway cannot decide which type the column actually has.","triggerScenarios":"class S(pw.Schema): v: int = pw.column_definition(dtype=float) — annotation says int, definition says float. Also mismatched generic parameters like annotation Optional[int] vs dtype=Optional[float], or str vs Any where dtypes compare unequal.","commonSituations":"Copy-pasting column_definition blocks between differently annotated fields; partially migrating an annotation after changing the dtype= argument.","solutions":["Make annotation and column_definition(dtype=...) identical, or drop one of them: annotate only (v: int) or define dtype only in column_definition.","Prefer the annotation as the single source of truth and use column_definition only for options (default_value, primary_key, description).","For complex types (Optional, List, Tuple), double-check both sides use the same pathway type classes."],"exampleFix":"# before\nclass S(pw.Schema):\n    v: int = pw.column_definition(dtype=float)\n\n# after\nclass S(pw.Schema):\n    v: int = pw.column_definition(default_value=0)  # dtype comes from annotation","handlingStrategy":"validation","validationCode":"from pathway.internals import dtype as dt\n\ndef annotation_matches_definition(annotation, column) -> bool:\n    return column.dtype is None or dt.wrap(annotation) == column.dtype","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick one source of truth for dtypes (the annotation) and omit dtype= in column_definition.","Run a quick import-time smoke test of every schema module so mismatches fail fast in CI."],"tags":["pathway","schema","dtype","type-annotation"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}