pathwaycom/pathway · error · ValueError
'topic' must be a non-empty string; got an empty list. Kafka
Error message
'topic' must be a non-empty string; got an empty list. Kafka does not allow empty topic names.
What it means
pw.io.kafka.read tolerates a list-valued 'topic' argument for backward compatibility (using the first element with a DeprecationWarning), but an empty list carries no topic at all and is rejected: Kafka does not permit empty topic names, and Pathway raises ValueError before the consumer would fail less clearly.
Source
Thrown at python/pathway/io/kafka/__init__.py:349
)
topic = topic_names
elif isinstance(topic_names, (list, tuple)):
warnings.warn(
"'topic_names' is deprecated; please use 'topic' instead. "
"Only the first element of the provided list is used as "
"the topic name.",
DeprecationWarning,
stacklevel=_stacklevel + 4,
)
topic = topic_names[0]
else:
raise TypeError(
f"'topic_names' must be a str or a list of str; got "
f"{type(topic_names).__name__}"
)
if isinstance(topic, list):
if not topic:
raise ValueError(
"'topic' must be a non-empty string; got an empty list. "
"Kafka does not allow empty topic names."
)
warnings.warn(
"'topic' should be a str, not list. First element will be used.",
DeprecationWarning,
stacklevel=_stacklevel + 4,
)
topic = topic[0]
if not isinstance(topic, str) or not topic:
raise ValueError(
f"'topic' must be a non-empty string; got {topic!r}. "
"Kafka does not allow empty topic names."
)
check_deprecated_kwargs(kwargs, ["topic_names"], stacklevel=_stacklevel + 4)
View on GitHub (pinned to fa2f74a464)
Solutions
- Pass a non-empty string: topic='test-topic'.
- If topics come from config, validate non-emptiness before calling read and fail with your own actionable message.
- Migrate away from list-valued topic entirely — only the first element was ever used.
Example fix
# before topics = [] # populated dynamically, ended up empty t = pw.io.kafka.read(rdkafka_settings, topic=topics) # after topics = ["test-topic"] t = pw.io.kafka.read(rdkafka_settings, topic=topics[0])
Defensive patterns
Strategy: validation
Validate before calling
if isinstance(topic, list):
if not topic:
raise SystemExit("topic list is empty; provide at least one topic name")
topic = topic[0]
t = pw.io.kafka.read(rdkafka_settings, topic=topic) Type guard
def usable_topic(v) -> bool:
return (isinstance(v, str) and bool(v)) or (isinstance(v, list) and len(v) > 0) Prevention
- Pass topic as a plain string, not a list.
- Guard dynamically built topic lists for non-emptiness before calling read.
When it happens
Trigger: pw.io.kafka.read(rdkafka_settings, topic=[]) — an empty list is detected before the first-element fallback runs. Contrast with topic=['a'] which only warns, and topic='' which hits the string check instead.
Common situations: Building the topic list dynamically (e.g. from an environment variable or subscription registry) and passing it through when it happens to be empty; refactoring code that used to pass a list of topics and now passes zero.
Related errors
- Failed to install dependencies
- Column {pseudocolumn} has to contain integers only.
- Column {api.TIME_PSEUDOCOLUMN} cannot contain negative times
- You cannot use {dep.to_column_expression()} in this reduce s
- join condition should be of form <left_table>.<column> == <r
AI-assisted analysis of pathwaycom/pathway@fa2f74a464 (2026-08-15).
Data as JSON: /api/errors/3a83bdce195f4491.
Report an issue: GitHub.