ApeWorX / silverback

Blockchain automation library, and SDK for the Silverback Platform
https://apeworx.io/silverback
Apache License 2.0
85 stars 9 forks source link

bug: Cannot convert datapoint 'foo' of type '<class 'str'>' #106

Closed mikeshultz closed 1 month ago

mikeshultz commented 1 month ago

This may not actually be a bug, but I figure it's worth reporting anyway. Returning a dict from a task handler like return {"foo": "bar"} will fail, because str is not an allowed return type (ScalarDatapoint).

024-08-09T01:20:16 WARNING: Cannot convert datapoint 'foo' of type '<class 'str'>': 4 validation errors for ScalarDatapoint
data.bool
  Input should be a valid boolean, unable to interpret input [type=bool_parsing, input_value='bar', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/bool_parsing
data.constrained-int
  Input should be a valid integer, unable to parse string as an integer [type=int_parsing, input_value='bar', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/int_parsing
data.float
  Input should be a valid number, unable to parse string as a number [type=float_parsing, input_value='bar', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/float_parsing
data.decimal
  Input should be a valid decimal [type=decimal_parsing, input_value='bar', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/decimal_parsing

Here:

https://github.com/ApeWorX/silverback/blob/2c6f2bc5a15e7b77c79add99d8493c8be760c4b3/silverback/types.py#L55-L60

Returning a str as a value causes an error on the entire task and results aren't handled. I wonder if there's some alternative here, like either stripping reference types, allowing these, or maybe failing a bit more gracefully.

CC @fubuloubu

linear[bot] commented 1 month ago

SBK-514 bug: Cannot convert datapoint 'foo' of type '<class 'str'>'

mikeshultz commented 1 month ago

This might be a non-issue. Warning is here:

https://github.com/ApeWorX/silverback/blob/2c6f2bc5a15e7b77c79add99d8493c8be760c4b3/silverback/types.py#L90-L94

This is the graceful handling. My problem might be elsewhere. Will update when I learn more.

mikeshultz commented 1 month ago

I'm closing this because it's already gracefully handling strings.

fubuloubu commented 1 month ago

This might need to be better documented, the intent is to only allow metric data that can be plotted via the dashboarding system

The suggestion could be anything that can be turned into a label identifier such as a hex bytestring or address can be a key, so that is the recommended way you should capture things for plotting purposes