{"record":{"id":"5363ea32be260429","repo":"pathwaycom/pathway","slug":"the-column-should-be-of-the-type-bytes","errorCode":null,"errorMessage":"The column should be of the type 'bytes'","messagePattern":"The column should be of the type 'bytes'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/io/pubsub/__init__.py","lineNumber":133,"sourceCode":"    >>> topic = publisher.create_topic(request={\"name\": topic_path})  # doctest: +SKIP\n\n    After that you can configure the table output with the following code:\n\n    >>> import pathway as pw\n    >>> pw.io.pubsub.write(table, publisher, project_id, topic_id)  # doctest: +SKIP\n\n    At last, don't forget to add ``pw.run()`` to run your pipeline.\n    \"\"\"\n\n    columns = list(table._columns.values())\n    if len(columns) != 1:\n        raise ValueError(\n            f\"Unexpected number of columns in table: {len(table._columns)}\"\n        )\n\n    allowed_column_types = (dt.BYTES, dt.ANY)\n    if columns[0].dtype not in allowed_column_types:\n        raise ValueError(\"The column should be of the type 'bytes'\")\n\n    output_buffer = _OutputBuffer(publisher, project_id, topic_id)\n    subscribe(\n        table,\n        on_change=output_buffer.on_change,\n        on_time_end=output_buffer.on_time_end,\n        name=name,\n        sort_by=sort_by,\n    )\n","sourceCodeStart":115,"sourceCodeEnd":143,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/io/pubsub/__init__.py#L115-L143","documentation":"Raised by pw.io.pubsub.write when the table's single column has a dtype other than dt.BYTES or dt.ANY. Pub/Sub message payloads are opaque bytes, so str/int/float/bool/JSON-typed columns are rejected at setup time; dt.ANY is tolerated because its runtime type is checked later in the callback.","triggerScenarios":"pw.io.pubsub.write(t, ...) where the single column is typed str, int, float, or any non-BYTES dtype — e.g. t.select(data=t.some_str_column) or a schema declaring value: str.","commonSituations":"Publishing text payloads without encoding to bytes first; passing a JSON-string column (dtype str) instead of a bytes column; schemas inferred from CSV/JSON where strings map to dt.STRING.","solutions":["Convert the column to bytes before writing: encode strings with an apply/astype into a bytes column, or declare it as bytes in the schema and encode at ingest.","For string payloads, encode explicitly at the source (e.g. .encode('utf-8') before the value enters the table).","If the type genuinely varies, type the column as dt.ANY and ensure runtime values are bytes (the runtime check will then enforce it)."],"exampleFix":"# before\nclass S(pw.Schema):\n    data: str\npw.io.pubsub.write(t, publisher, project_id, topic_id)\n\n# after\nclass S(pw.Schema):\n    data: bytes\npw.io.pubsub.write(t, publisher, project_id, topic_id)","handlingStrategy":"validation","validationCode":"from pathway import dt\ncol = next(iter(t._columns.values()))\nassert col.dtype in (dt.BYTES, dt.ANY), f\"payload column must be bytes, got {col.dtype}\"\npw.io.pubsub.write(t, publisher, project_id, topic_id)","typeGuard":"def payload_is_bytes_compatible(t) -> bool:\n    from pathway import dt\n    col = next(iter(t._columns.values()))\n    return col.dtype in (dt.BYTES, dt.ANY)","tryCatchPattern":null,"preventionTips":["Declare payload fields as bytes in the schema and encode at ingest.","Convert string columns with an encode/astype step before the writer.","Don't rely on dt.ANY passing setup — runtime values must still be bytes."],"tags":["pathway","gcp","pubsub","type-mismatch","bytes"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}