{"record":{"id":"6664c12ec47cf8c1","repo":"pathwaycom/pathway","slug":"value-must-be-specified-if-key-is-not-none","errorCode":null,"errorMessage":"'value' must be specified if 'key' is not None","messagePattern":"'value' must be specified if 'key' is not None","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/io/_utils.py","lineNumber":571,"sourceCode":"            for column_name in table._columns:\n                cls.add_column_reference_to_extract(\n                    table[column_name], columns_to_extract, extracted_field_indices\n                )\n            table = table.select(*columns_to_extract)\n            data_format = api.DataFormat(\n                format_type=\"jsonlines\" if format == \"json\" else \"dsv\",\n                key_field_names=[],\n                value_fields=_format_output_value_fields(table),\n                delimiter=delimiter,\n                schema_registry_settings=maybe_schema_registry_settings(\n                    schema_registry_settings\n                ),\n                subject=subject,\n            )\n        elif format == \"raw\" or format == \"plaintext\":\n            value_field_index = None\n            if key is not None and value is None:\n                raise ValueError(\"'value' must be specified if 'key' is not None\")\n            if value is not None:\n                value_field_index = cls.add_column_reference_to_extract(\n                    value, columns_to_extract, extracted_field_indices\n                )\n            else:\n                column_names = list(table._columns.keys())\n                if len(column_names) != 1:\n                    raise ValueError(\n                        f\"'{format}' format without explicit 'value' specification \"\n                        \"can only be used with single-column tables\"\n                    )\n                value = table[column_names[0]]\n                value_field_index = cls.add_column_reference_to_extract(\n                    value, columns_to_extract, extracted_field_indices\n                )\n\n            table = table.select(*columns_to_extract)\n            if (","sourceCodeStart":553,"sourceCodeEnd":589,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/io/_utils.py#L553-L589","documentation":"Raised by MessageQueueOutputFormat.build for format='raw' or 'plaintext' when a 'key' column is given but 'value' is None. In raw/plaintext mode the message payload is exactly one designated column; when key is set you must say which column carries the payload too, because there is no unambiguous default in the presence of a key (the single-column auto-detection is only attempted when key is None).","triggerScenarios":"pw.io.kafka.write(t, ..., format='raw', key=pw.this.k) with no value on a multi-column table; copying key= from a json-format writer into a raw-format one.","commonSituations":"Keyed raw payloads (e.g. keyed binary blobs) where the author assumed the writer would guess the payload column; gradual addition of key= to an existing raw writer.","solutions":["Pass value=pw.this.payload alongside key=pw.this.k.","Or drop 'key' if keying is not needed and the table is single-column (auto-detection then applies)."],"exampleFix":"# before\npw.io.kafka.write(t, ..., format='raw', key=pw.this.k)\n\n# after\npw.io.kafka.write(t, ..., format='raw', key=pw.this.k, value=pw.this.payload)","handlingStrategy":"validation","validationCode":"if format in ('raw', 'plaintext') and key is not None:\n    assert value is not None, \"raw/plaintext output with a key requires an explicit value column\"","typeGuard":null,"tryCatchPattern":"try:\n    pw.io.kafka.write(t, ..., format='raw', key=pw.this.k)\nexcept ValueError as e:\n    if \"'value' must be specified\" in str(e):\n        pw.io.kafka.write(t, ..., format='raw', key=pw.this.k, value=pw.this.payload)\n    else:\n        raise","preventionTips":["Always pass key and value together for raw sinks.","Review raw-sink configs whenever adding key routing."],"tags":["pathway","kafka","raw","key-value","validation"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}