Skip to content

Commit

Permalink
Search: handle geometry serialization in unit results
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
japauliina authored and mhieta committed Oct 10, 2024
1 parent d334991 commit 886280d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions services/search/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 886280d

Please sign in to comment.