pathwaycom/pathway · error · ValueError

The MQTT topic to publish to must not be empty.

Error message

The MQTT topic to publish to must not be empty.

What it means

pw.io.mqtt.write publishes to a single concrete topic (or a per-row column via a ColumnReference); unlike subscribing, publishing to an empty topic is invalid MQTT, so the connector raises this ValueError when the topic argument is an empty string.

Source

Thrown at python/pathway/io/mqtt/__init__.py:331

    ...     "mqtt://localhost:1883/?client_id=test",
    ...     topic="test/topic",
    ...     format="plaintext",
    ...     value=table.owner,
    ... )

    Finally, if you'd like the topic to be dynamic and depend on the owner of the pet,
    you can specify this column definition as the topic:

    >>> pw.io.mqtt.write(
    ...     table,
    ...     "mqtt://localhost:1883/?client_id=test",
    ...     topic=table.owner,
    ...     format="json",
    ... )
    """
    if isinstance(topic, str):
        if topic == "":
            raise ValueError("The MQTT topic to publish to must not be empty.")
        if "+" in topic or "#" in topic:
            raise ValueError(
                "The MQTT topic to publish to must not contain the wildcard characters "
                f"'+' or '#' (got {topic!r}); wildcards are only allowed when reading "
                "(subscribing)."
            )
    output_format = MessageQueueOutputFormat.construct(
        table,
        format=format,
        delimiter=delimiter,
        value=value,
        topic_name=topic if isinstance(topic, ColumnReference) else None,
    )
    table = output_format.table

    data_storage = api.DataStorage(
        storage_type="mqtt",
        path=uri,

View on GitHub (pinned to fa2f74a464)

Solutions

  1. Set a concrete topic name, e.g. topic='alerts/high'
  2. For dynamic per-row topics, pass a ColumnReference instead: topic=table.owner
  3. Validate config before pipeline construction: if not topic: raise ValueError(...)

Example fix

# before
pw.io.mqtt.write(t, "mqtt://localhost:1883", topic="")

# after
pw.io.mqtt.write(t, "mqtt://localhost:1883", topic="alerts/high")
Defensive patterns

Strategy: validation

Validate before calling

if isinstance(topic, str):
    assert topic, "MQTT publish topic must be non-empty"
# column-based topics are data-driven and exempt

Type guard

def is_valid_publish_topic(topic) -> bool:
    if isinstance(topic, pw.ColumnReference):
        return True  # per-row topic, validated by data
    return isinstance(topic, str) and topic != ""

Prevention

When it happens

Trigger: Calling pw.io.mqtt.write(table, uri, topic='') — typically a topic read from configuration that defaulted to or was set to the empty string.

Common situations: Env-driven topic configuration that is unset in one environment (e.g. works locally, empty in CI); template strings where a topic component is missing.

Related errors


AI-assisted analysis of pathwaycom/pathway@fa2f74a464 (2026-08-15). Data as JSON: /api/errors/658627b544182a87. Report an issue: GitHub.