aiochclient icon indicating copy to clipboard operation
aiochclient copied to clipboard

Library does not accept subtypes

Open w0rp opened this issue 2 years ago • 2 comments
trafficstars

https://github.com/maximdanilchenko/aiochclient/blob/463533cdf41540f05b86ca0a7d0f287ef1a12513/aiochclient/types.py#L456

The library looks up types in a map using type(value) and raises an exception if the type does not exist in the map. This means any type derived from those types cannot be passed to the library. This creates errors at runtime for derived types that cannot be caught by type checkers. A common example will be StrEnum values, which are a subtype of str.

It's better to use isinstance(value, tuple(PY_TYPES_MAPPING)) to check for compatible types, and ensure that the underlying connection to ClickHouse accepts the types.

w0rp avatar Sep 06 '23 11:09 w0rp

I'll also note that bool is a subtype of int, and you may wish to add unit tests to ensure that bool values are sent to ClickHouse correctly, or you could end up with errors where True becomes 1, and so on. I haven't investigated thoroughly to know whether there are any problems with bool or not, I just thought I'd mention it in case it helps.

w0rp avatar Sep 06 '23 11:09 w0rp

@maximdanilchenko I think its good idea to allow insert enum's and call .value for them before insert.

Without this option client always must call .value by himself for every enum value.

If its relevant i can do this.

Maksim-Burtsev avatar Dec 03 '23 07:12 Maksim-Burtsev