ApiLogicServer-src icon indicating copy to clipboard operation
ApiLogicServer-src copied to clipboard

Postgres unknown object timedelta

Open valhuber opened this issue 1 year ago • 2 comments

Loading the docker postgres stress shows log with many of:

JSON Encoding Error: Unknown object type "<class 'datetime.timedelta'>" for 0:00:00
JSON Encoding Error: Unknown object type "<class 'datetime.timedelta'>" for 0:00:00
JSON Encoding Error: Unknown object type "<class 'datetime.timedelta'>" for 0:00:00

valhuber avatar Dec 08 '23 20:12 valhuber

Per screen shot below, this appears to be coming from safrs; unclear how to resolve.

JSON encoding error

postgres-stress.zip

valhuber avatar Dec 11 '23 18:12 valhuber

Hi,

In case of json encoding errors like this you can write a custom JSON encoder for flask/safrs and use that (set app.json_encoder, cfr. https://github.com/thomaxxl/safrs/blob/714708ae9b6eb5a86517c867b32caeea8d05e681/safrs/json_encoder.py#L156 ).

Note that in DEBUG mode, the encoding will default to str(), if safrs isn't running in debug then you will get an error.

I added a timedelta encoding to safrs (https://github.com/thomaxxl/safrs/commit/56f3839fd5427420102d4676b0b5326db6bca184) .

The json encoding (patch/post) will fail though.

thomaxxl avatar Dec 12 '23 07:12 thomaxxl