Skip to content

Commit fa5738a

Browse files
authored
fix(json_api): correctly find id before retrieving related_url (#162)
1 parent 1b76a9f commit fa5738a

File tree

1 file changed

+4
-2
lines changed
  • src/agent_toolkit/forestadmin/agent_toolkit/services/serializers

1 file changed

+4
-2
lines changed

src/agent_toolkit/forestadmin/agent_toolkit/services/serializers/json_api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,12 @@ def schema(self) -> "ForestSchema":
155155
)
156156

157157
def get_related_url(self, obj: Any):
158-
if "data" in obj:
158+
if "id" in obj:
159+
obj["__forest_id__"] = obj["id"]
160+
elif "data" in obj:
159161
obj["__forest_id__"] = obj["data"]["id"]
160162
else:
161-
obj["__forest_id__"] = obj["id"]
163+
raise JsonApiException("Cannot find json api 'id' in given obj.")
162164
res: Any = super(ForestRelationShip, self).get_related_url(obj) # type: ignore
163165
del obj["__forest_id__"]
164166
return {"href": res}

0 commit comments

Comments
 (0)