pathwaycom/pathway · error · TypeError
'topic_names' must be a str or a list of str; got {type(topi
Error message
'topic_names' must be a str or a list of str; got {type(topic_names).__name__} What it means
The deprecated 'topic_names' alias in pw.io.kafka.read accepts only a string or a list/tuple of strings (of which just the first element is used, with a warning). Passing any other type — an int, dict, set, None-with-other-keys, etc. — raises TypeError naming the offending type.
Source
Thrown at python/pathway/io/kafka/__init__.py:343
raise ValueError("Missing topic name specification")
if isinstance(topic_names, str):
warnings.warn(
"'topic_names' is deprecated; please use 'topic' instead.",
DeprecationWarning,
stacklevel=_stacklevel + 4,
)
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(View on GitHub (pinned to fa2f74a464)
Solutions
- Migrate to the modern parameter: pw.io.kafka.read(rdkafka_settings, topic='test-topic').
- If you must keep topic_names, pass a single string, not a collection or other object.
- Note that even a valid list only uses its first element — migrate to topic= to avoid silently dropping topics.
Example fix
# before t = pw.io.kafka.read(rdkafka_settings, topic_names=["a", "b"]) # after t = pw.io.kafka.read(rdkafka_settings, topic="a")
Defensive patterns
Strategy: type-guard
Validate before calling
if topic_names is not None and not isinstance(topic_names, (str, list, tuple)):
raise SystemExit(f"topic_names must be str or list of str, got {type(topic_names).__name__}") Type guard
def valid_topic_names(v) -> bool:
return v is None or isinstance(v, (str, list, tuple)) Prevention
- Migrate off the deprecated topic_names alias — use topic='name'.
- Remember list-valued topic_names only ever used the first element.
When it happens
Trigger: pw.io.kafka.read(rdkafka_settings, topic_names=0), topic_names={'t1': 1}, or topic_names=set(['a']). The check happens after the str and (list, tuple) branches, so only non-str non-sequence types reach it.
Common situations: Passing a pandas/numpy object or a config structure where a string was expected; reusing the deprecated alias from very old Pathway code with unusual payload types.
Related errors
- Got unexpected keyword argument 'topic_name'. pw.io.kafka.re
- Missing topic name specification
- 'topic' must be a non-empty string; got an empty list. Kafka
- 'simple_read' does not accept {forbidden!r}. If you need to
- 'read_only_new=True' together with mode='static' is self-con
AI-assisted analysis of pathwaycom/pathway@fa2f74a464 (2026-08-15).
Data as JSON: /api/errors/264a2f710a299452.
Report an issue: GitHub.