{"record":{"id":"4581ac6d9a60b33b","repo":"pathwaycom/pathway","slug":"you-can-t-use-a-column-of-type-instance-dtype-as","errorCode":null,"errorMessage":"You can't use a column of type {instance_dtype} as instance in AsyncTransformer because it is unhashable.","messagePattern":"You can't use a column of type (.+?) as instance in AsyncTransformer because it is unhashable\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/stdlib/utils/async_transformer.py","lineNumber":445,"sourceCode":"        autocommit_duration_ms: int | None = 1500,\n        _event_loop: asyncio.AbstractEventLoop | None = None,\n    ) -> None:\n        super().__init__(\n            autocommit_duration_ms=autocommit_duration_ms, _event_loop=_event_loop\n        )\n\n        # TODO: when AsyncTransformer uses persistence backend for cache\n        # just take the settings for persistence config\n        # Use DefaultCache for now as the only available option\n        self._connector.set_options(cache_strategy=udfs.DefaultCache())\n\n        sig = inspect.signature(self.invoke)\n        self._check_signature_matches_schema(sig, input_table.schema)\n\n        input_table = input_table.with_columns(**{_INSTANCE_COLUMN: instance})\n        instance_dtype = eval_type(input_table[_INSTANCE_COLUMN])\n        if not dt.is_hashable_in_python(instance_dtype):\n            raise ValueError(\n                f\"You can't use a column of type {instance_dtype} as instance in\"\n                + \" AsyncTransformer because it is unhashable.\"\n            )\n\n        self._input_table = input_table\n\n    def _check_signature_matches_schema(\n        self, sig: inspect.Signature, schema: type[Schema]\n    ) -> None:\n        try:\n            sig.bind(**schema.columns())\n        except TypeError as e:\n            msg = str(e)\n            if match := re.match(\"got an unexpected keyword argument '(.+)'\", msg):\n                column = match[1]\n                raise TypeError(\n                    f\"Input table has a column {column!r} but it is not present\"\n                    + \" on the argument list of the invoke method.\"","sourceCodeStart":427,"sourceCodeEnd":463,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/stdlib/utils/async_transformer.py#L427-L463","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a hashable column as instance, e.g. a string/int id or a URL column","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","Alternatively hash the payload in the source connector before it enters Pathway"],"exampleFix":"# before\nt = pw.io.http.read(...).json_parse('payload')\nout = Enrich(t, instance=t.payload)  # payload is pw.Json -> unhashable\n\n# after\nt = t.with_columns(key=t.payload.apply(json.dumps, return_type=str))\nout = Enrich(t, instance=t.key)","handlingStrategy":"type-guard","validationCode":"from pathway import dt\ninstance_dtype = dt.eval_type(input_table[instance_column])\nassert dt.is_hashable_in_python(instance_dtype), f'{instance_column} ({instance_dtype}) is unhashable; use a str/int key'","typeGuard":"def is_hashable_instance_column(table: pw.Table, col: str) -> bool:\n    from pathway import dt\n    return dt.is_hashable_in_python(dt.eval_type(table[col]))","tryCatchPattern":null,"preventionTips":["Default to a natural key column (id, url, hash) as instance, never a Json/list column","If only a JSON payload exists, precompute key = payload.apply(json.dumps, return_type=str)","Add a construction-time assert on dt.eval_type of the instance column in shared helper code"],"tags":["pathway","async","async-transformer","hashability","json"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}