pathwaycom/pathway · error · ValueError
'topic_name' must be a non-empty string; got an empty string
Error message
'topic_name' must be a non-empty string; got an empty string. Kafka does not allow empty topic names.
What it means
pw.io.kafka.write rejects an empty-string topic_name because Kafka does not allow zero-length topic names. Note this check only covers str inputs (isinstance(topic_name, str) and not topic_name) — a non-string topic_name is passed through and handled downstream, e.g. a ColumnReference is allowed for per-row topic routing.
Source
Thrown at python/pathway/io/kafka/__init__.py:717
>>> pw.io.kafka.write(
... t2,
... rdkafka_settings,
... "test",
... format="raw",
... key=t2.bar,
... value=t2.foo,
... headers=[t2.baz],
... )
"""
if not rdkafka_settings.get("bootstrap.servers"):
raise ValueError(
"rdkafka_settings must contain a non-empty 'bootstrap.servers' "
"entry so the producer can locate a broker; got "
f"{rdkafka_settings.get('bootstrap.servers')!r}."
)
if isinstance(topic_name, str) and not topic_name:
raise ValueError(
"'topic_name' must be a non-empty string; got an empty string. "
"Kafka does not allow empty topic names."
)
output_format = MessageQueueOutputFormat.construct(
table,
format=format,
delimiter=delimiter,
key=key,
value=value,
headers=headers,
topic_name=topic_name if isinstance(topic_name, ColumnReference) else None,
schema_registry_settings=schema_registry_settings,
subject=subject,
)
output_table = output_format.table
remapped_sort_by = _remap_sort_by(sort_by, table, output_table)
View on GitHub (pinned to fa2f74a464)
Solutions
- Pass a concrete topic name: pw.io.kafka.write(table, rdkafka_settings, 'test', format='raw').
- Default config values at load time: topic_name = os.environ.get('KAFKA_TOPIC') or 'test'.
- Kafka topic names must match [a-zA-Z0-9._-]{1,255} — validate user-supplied names against that pattern.
Example fix
# before
topic_name = os.environ.get("KAFKA_OUTPUT_TOPIC") # unset -> None/''
pw.io.kafka.write(t, rdkafka_settings, topic_name or "", format="raw")
# after
topic_name = os.environ.get("KAFKA_OUTPUT_TOPIC") or "test"
pw.io.kafka.write(t, rdkafka_settings, topic_name, format="raw") Defensive patterns
Strategy: validation
Validate before calling
if isinstance(topic_name, str) and not topic_name:
raise SystemExit("topic_name must be a non-empty Kafka topic name")
pw.io.kafka.write(table, rdkafka_settings, topic_name, format="raw") Type guard
def valid_write_topic(v) -> bool:
import re
if isinstance(v, str):
return bool(re.match(r"^[a-zA-Z0-9._-]{1,255}$", v))
return v is not None # ColumnReference allowed for per-row routing Prevention
- Remember write uses 'topic_name' while read uses 'topic'.
- Default output topics from env with a fail-fast check, never an empty string.
- Validate against Kafka's topic charset before deployment.
When it happens
Trigger: pw.io.kafka.write(table, rdkafka_settings, '', format='raw') — literal empty string; or topic_name computed from config that resolved to ''.
Common situations: Topic name from an unset env variable defaulting to ''; whitespace-only or accidentally cleared config value; templated deployment where the topic variable was not interpolated. Remember write uses 'topic_name' while read uses 'topic'.
Related errors
- Failed to install dependencies
- Column {api.TIME_PSEUDOCOLUMN} cannot contain negative times
- 'subject' must be a non-empty string; got an empty string. S
- 'topic' must be a non-empty string; got {topic!r}. Kafka doe
- Column {pseudocolumn} has to contain integers only.
AI-assisted analysis of pathwaycom/pathway@fa2f74a464 (2026-08-15).
Data as JSON: /api/errors/46b26f837e75d89c.
Report an issue: GitHub.