Skip to content

Commit 59a8350

Browse files
author
Remco Meeuwissen
committed
Updated a few places I missed last time with the decimal.Decimal orjson fix
1 parent c856a09 commit 59a8350

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

tipg/factory.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
)
3636
from tipg.errors import MissingGeometryColumn, NoPrimaryKey, NotFound
3737
from tipg.resources.enums import MediaType
38-
from tipg.resources.response import GeoJSONResponse, SchemaJSONResponse
38+
from tipg.resources.response import GeoJSONResponse, SchemaJSONResponse, orjsonDumps
3939
from tipg.settings import FeaturesSettings, MVTSettings, TMSSettings
4040

4141
from fastapi import APIRouter, Depends, Path, Query
@@ -781,7 +781,7 @@ async def items( # noqa: C901
781781
# NDJSON Response
782782
if output_type == MediaType.ndjson:
783783
return StreamingResponse(
784-
(orjson.dumps(row) + b"\n" for row in rows),
784+
(orjsonDumps(row) + b"\n" for row in rows),
785785
media_type=MediaType.ndjson,
786786
headers={
787787
"Content-Disposition": "attachment;filename=items.ndjson"
@@ -892,7 +892,7 @@ async def items( # noqa: C901
892892
# GeoJSONSeq Response
893893
elif output_type == MediaType.geojsonseq:
894894
return StreamingResponse(
895-
(orjson.dumps(f) + b"\n" for f in data["features"]), # type: ignore
895+
(orjsonDumps(f) + b"\n" for f in data["features"]), # type: ignore
896896
media_type=MediaType.geojsonseq,
897897
headers={
898898
"Content-Disposition": "attachment;filename=items.geojson"
@@ -1016,7 +1016,7 @@ async def item(
10161016
# NDJSON Response
10171017
if output_type == MediaType.ndjson:
10181018
return StreamingResponse(
1019-
(orjson.dumps(row) + b"\n" for row in rows),
1019+
(orjsonDumps(row) + b"\n" for row in rows),
10201020
media_type=MediaType.ndjson,
10211021
headers={
10221022
"Content-Disposition": "attachment;filename=items.ndjson"
@@ -1512,7 +1512,6 @@ async def collection_get_tile(
15121512
return Response(bytes(tile), media_type=MediaType.mvt.value)
15131513

15141514
def _tilejson_routes(self):
1515-
15161515
############################################################################
15171516
# ADDITIONAL ENDPOINTS NOT IN OGC Tiles API (tilejson, style.json, viewer) #
15181517
############################################################################

tipg/resources/response.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,20 @@ def default(obj):
1414
return str(obj)
1515

1616

17+
def orjsonDumps(content: Any):
18+
return orjson.dumps(
19+
content,
20+
default=default,
21+
option=orjson.OPT_NON_STR_KEYS | orjson.OPT_SERIALIZE_NUMPY,
22+
)
23+
24+
1725
class ORJSONResponse(JSONResponse):
1826
"""Custom response handler for using orjson"""
1927

2028
def render(self, content: Any) -> bytes:
2129
"""Render the content into a JSON response using orjson"""
22-
return orjson.dumps(
23-
content,
24-
default=default,
25-
option=orjson.OPT_NON_STR_KEYS | orjson.OPT_SERIALIZE_NUMPY,
26-
)
30+
return orjsonDumps(content)
2731

2832

2933
class GeoJSONResponse(ORJSONResponse):

0 commit comments

Comments
 (0)