Skip to content

Commit

Permalink
Updated a few places I missed last time with the decimal.Decimal orjs…
Browse files Browse the repository at this point in the history
…on fix
  • Loading branch information
Remco Meeuwissen committed Dec 14, 2023
1 parent c856a09 commit 59a8350
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
9 changes: 4 additions & 5 deletions tipg/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
)
from tipg.errors import MissingGeometryColumn, NoPrimaryKey, NotFound
from tipg.resources.enums import MediaType
from tipg.resources.response import GeoJSONResponse, SchemaJSONResponse
from tipg.resources.response import GeoJSONResponse, SchemaJSONResponse, orjsonDumps
from tipg.settings import FeaturesSettings, MVTSettings, TMSSettings

from fastapi import APIRouter, Depends, Path, Query
Expand Down Expand Up @@ -781,7 +781,7 @@ async def items( # noqa: C901
# NDJSON Response
if output_type == MediaType.ndjson:
return StreamingResponse(
(orjson.dumps(row) + b"\n" for row in rows),
(orjsonDumps(row) + b"\n" for row in rows),
media_type=MediaType.ndjson,
headers={
"Content-Disposition": "attachment;filename=items.ndjson"
Expand Down Expand Up @@ -892,7 +892,7 @@ async def items( # noqa: C901
# GeoJSONSeq Response
elif output_type == MediaType.geojsonseq:
return StreamingResponse(
(orjson.dumps(f) + b"\n" for f in data["features"]), # type: ignore
(orjsonDumps(f) + b"\n" for f in data["features"]), # type: ignore
media_type=MediaType.geojsonseq,
headers={
"Content-Disposition": "attachment;filename=items.geojson"
Expand Down Expand Up @@ -1016,7 +1016,7 @@ async def item(
# NDJSON Response
if output_type == MediaType.ndjson:
return StreamingResponse(
(orjson.dumps(row) + b"\n" for row in rows),
(orjsonDumps(row) + b"\n" for row in rows),
media_type=MediaType.ndjson,
headers={
"Content-Disposition": "attachment;filename=items.ndjson"
Expand Down Expand Up @@ -1512,7 +1512,6 @@ async def collection_get_tile(
return Response(bytes(tile), media_type=MediaType.mvt.value)

def _tilejson_routes(self):

############################################################################
# ADDITIONAL ENDPOINTS NOT IN OGC Tiles API (tilejson, style.json, viewer) #
############################################################################
Expand Down
14 changes: 9 additions & 5 deletions tipg/resources/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ def default(obj):
return str(obj)


def orjsonDumps(content: Any):
return orjson.dumps(
content,
default=default,
option=orjson.OPT_NON_STR_KEYS | orjson.OPT_SERIALIZE_NUMPY,
)


class ORJSONResponse(JSONResponse):
"""Custom response handler for using orjson"""

def render(self, content: Any) -> bytes:
"""Render the content into a JSON response using orjson"""
return orjson.dumps(
content,
default=default,
option=orjson.OPT_NON_STR_KEYS | orjson.OPT_SERIALIZE_NUMPY,
)
return orjsonDumps(content)


class GeoJSONResponse(ORJSONResponse):
Expand Down

0 comments on commit 59a8350

Please sign in to comment.