pathwaycom/pathway · error · ValueError

You can't use a column of type {instance_dtype} as instance

Error message

You can't use a column of type {instance_dtype} as instance in AsyncTransformer because it is unhashable.

What it means

AsyncTransformer's instance= argument names a column whose values key the per-instance deduplication/caching of async calls, so its dtype must be hashable in Python. After materializing the instance column, the constructor evaluates its dtype and checks dt.is_hashable_in_python; composite dtypes such as pw.Json, lists, or arrays are unhashable and raise this ValueError at setup time.

Source

Thrown at python/pathway/stdlib/utils/async_transformer.py:445

        autocommit_duration_ms: int | None = 1500,
        _event_loop: asyncio.AbstractEventLoop | None = None,
    ) -> None:
        super().__init__(
            autocommit_duration_ms=autocommit_duration_ms, _event_loop=_event_loop
        )

        # TODO: when AsyncTransformer uses persistence backend for cache
        # just take the settings for persistence config
        # Use DefaultCache for now as the only available option
        self._connector.set_options(cache_strategy=udfs.DefaultCache())

        sig = inspect.signature(self.invoke)
        self._check_signature_matches_schema(sig, input_table.schema)

        input_table = input_table.with_columns(**{_INSTANCE_COLUMN: instance})
        instance_dtype = eval_type(input_table[_INSTANCE_COLUMN])
        if not dt.is_hashable_in_python(instance_dtype):
            raise ValueError(
                f"You can't use a column of type {instance_dtype} as instance in"
                + " AsyncTransformer because it is unhashable."
            )

        self._input_table = input_table

    def _check_signature_matches_schema(
        self, sig: inspect.Signature, schema: type[Schema]
    ) -> None:
        try:
            sig.bind(**schema.columns())
        except TypeError as e:
            msg = str(e)
            if match := re.match("got an unexpected keyword argument '(.+)'", msg):
                column = match[1]
                raise TypeError(
                    f"Input table has a column {column!r} but it is not present"
                    + " on the argument list of the invoke method."

View on GitHub (pinned to fa2f74a464)

Solutions

  1. Pass a hashable column as instance, e.g. a string/int id or a URL column
  2. If only a JSON payload is available, derive a hashable key first: input_table.with_columns(key=input_table.payload.apply(json.dumps, return_type=str)) and use that column
  3. Alternatively hash the payload in the source connector before it enters Pathway

Example fix

# before
t = pw.io.http.read(...).json_parse('payload')
out = Enrich(t, instance=t.payload)  # payload is pw.Json -> unhashable

# after
t = t.with_columns(key=t.payload.apply(json.dumps, return_type=str))
out = Enrich(t, instance=t.key)
Defensive patterns

Strategy: type-guard

Validate before calling

from pathway import dt
instance_dtype = dt.eval_type(input_table[instance_column])
assert dt.is_hashable_in_python(instance_dtype), f'{instance_column} ({instance_dtype}) is unhashable; use a str/int key'

Type guard

def is_hashable_instance_column(table: pw.Table, col: str) -> bool:
    from pathway import dt
    return dt.is_hashable_in_python(dt.eval_type(table[col]))

Prevention

When it happens

Trigger: Calling pw.AsyncTransformer(input_table, instance=input_table.payload) where payload has dtype pw.Json or a list/array dtype; passing a column produced by .json_parse(); passing a tuple-typed column.

Common situations: Keying API calls on a whole JSON payload (common with LLM prompt columns) instead of a hashable id; document/embedding columns of type array; schemas inferred from REST connectors where the natural key column is a JSON object.

Related errors


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