pathway icon indicating copy to clipboard operation
pathway copied to clipboard

[Bug]: TypeError: Cannot instantiate typing.Any

Open nikitos opened this issue 7 months ago • 4 comments

Steps to reproduce

in pw.io.http.rest_connector if no schema was provided default is: https://github.com/pathwaycom/pathway/blob/6bcee7efd35dc3d6586160df1a0641b0d55fa8ff/python/pathway/io/http/_server.py#L832 but deserialising is imposible to typing.Any here: https://github.com/pathwaycom/pathway/blob/6bcee7efd35dc3d6586160df1a0641b0d55fa8ff/python/pathway/io/http/_server.py#L479

Relevant log output

ERROR:root:Failed to cast column 'query' to type 'typing.Any'
Traceback (most recent call last):
  File "/Users/nikitos/.pyenv/versions/pathway3/lib/python3.10/site-packages/pathway/io/http/_server.py", line 480, in _cast_types_to_schema
    payload[column] = exact_type(payload[column])
  File "/Users/nikitos/.pyenv/versions/3.10.19/lib/python3.10/typing.py", line 387, in __call__
    raise TypeError(f"Cannot instantiate {self!r}")
TypeError: Cannot instantiate typing.Any

What did you expect to happen?

i temporary use this hack, but not sure is it right: payload[column] = payload[column] if exact_type == typing.Any else exact_type(payload[column])

Version

0.30.1

Docker Versions (if used)

No response

OS

MacOS

On which CPU architecture did you run Pathway?

ARM64 (AArch64, Apple silicon)

nikitos avatar May 01 '26 08:05 nikitos

Hello @nikitos,

Thank you for your interest in Pathway framework and for the bug reported.

It will be fixed in the soonest release.

zxqfd555 avatar May 04 '26 12:05 zxqfd555

We've merged the PR with the fix. The nightly version should already have the issue fixed.

zxqfd555 avatar May 22 '26 13:05 zxqfd555

can not check right now, move to bytewax instead (not because if this bug)

nikitos avatar May 26 '26 12:05 nikitos

This looks already fixed on main. _cast_types_to_schema now skips Any-typed columns instead of calling the type as a constructor:

https://github.com/pathwaycom/pathway/blob/main/python/pathway/io/http/_server.py#L481-L482

exact_type = unoptionalize(dtype).typehint
if exact_type is Any:
    continue
payload[column] = exact_type(payload[column])

which is exactly the guard suggested in the report. It's also noted in the CHANGELOG: "pw.io.http.rest_connector no longer raises TypeError: Cannot instantiate typing.Any when a request column has the inferred default schema type (Any)." So this can probably be closed. (Reproduced the original crash against 0.30.1 and confirmed it no longer occurs on current main.)

linhongyu510 avatar Sep 23 '26 13:09 linhongyu510