ApiLogicServer / ApiLogicServer-src

Create an executable project (API and Admin App) from a database or natural language prompt with 1 command, customize with declarative rules and Python in your IDE, containerize and deploy.
https://apilogicserver.github.io/Docs/
BSD 3-Clause "New" or "Revised" License
30 stars 5 forks source link

Postgres unknown object timedelta #32

Open valhuber opened 11 months ago

valhuber commented 11 months ago

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 commented 11 months ago

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

JSON encoding error

postgres-stress.zip

thomaxxl commented 11 months ago

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.