Skip to content

Commit

Permalink
Search: handle department & municipality serialization in unit results
Browse files Browse the repository at this point in the history
The issue was noticed when using `include=unit.department` in search
raised "Object of type Department is not JSON serializable" errors. Add
department and municipality serialization to the search results to fix
the issue.
  • Loading branch information
japauliina authored and mhieta committed Aug 9, 2024
1 parent 79b80b2 commit c428efd
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions services/search/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ def to_representation(self, obj):
representation["connections"] = UnitConnectionSerializer(
obj.connections, many=True
).data
elif "department" in include_field:
representation["department"] = DepartmentSerializer(
obj.department
).data
elif "municipality" in include_field:
representation["municipality"] = obj.municipality.id
else:
if hasattr(obj, include_field):
representation[include_field] = getattr(
Expand Down

0 comments on commit c428efd

Please sign in to comment.