From 886280dfedd2b85dfba40964a6c711dab7129d9d Mon Sep 17 00:00:00 2001 From: Pauliina Ilmanen Date: Thu, 10 Oct 2024 15:00:14 +0300 Subject: [PATCH] Search: handle geometry serialization in unit results The issue was noticed when using `include=unit.geometry` in search raised "Object of type MultiLineString is not JSON serializable" errors. Add geometry and geometry_3d serialization to the search results to fix the issue. --- services/search/api.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/services/search/api.py b/services/search/api.py index 76d2e39d..2de0ee10 100644 --- a/services/search/api.py +++ b/services/search/api.py @@ -205,6 +205,16 @@ def to_representation(self, obj): ).data elif "municipality" in include_field: representation["municipality"] = obj.municipality.id + elif "geometry_3d" in include_field: + if obj.geometry_3d: + representation["geometry_3d"] = munigeo_api.geom_to_json( + obj.geometry_3d, DEFAULT_SRS + ) + elif "geometry" in include_field: + if obj.geometry: + representation["geometry"] = munigeo_api.geom_to_json( + obj.geometry, DEFAULT_SRS + ) else: if hasattr(obj, include_field): representation[include_field] = getattr(