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.
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.