developmentseed / tipg

Simple and Fast Geospatial OGC Features and Tiles API for PostGIS.
https://developmentseed.org/tipg/
MIT License
153 stars 23 forks source link

Fixed a bug where floats in the database would not be serialized corr… #89

Closed RemcoMeeuwissen closed 1 year ago

RemcoMeeuwissen commented 1 year ago

What I am changing

Ran into a bug where having a float in the database would cause a Type is not JSON serializable: decimal.Decimal error when requesting a json response.

How I did it

orjson has a default parameter when calling the dumps function which allows you to specify how to serialize unknown types, using this Decimal is now serialized to string.

Because the ORJsonResponse wrapper provided by fastapi does not support sending along this parameter I tweaked the GeoJSONResponse and SchemaJSONResponse classes to use orjson directly (basically recreating the wrapper, luckily it's fairly small).

How you can test it

I've added a number field to the my_data.sql fixture, this caused the bug to be triggered on existing tests so no new tests are needed.

vincentsarago commented 1 year ago

@RemcoMeeuwissen I've been away and focused on titiler for the past week, I'll try to have a look on all the contributions next week 🙏