Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def deserialize(self, data: DumpedResult, collection: Collection) -> RecordsData
ret = {}
data["data"] = cast(Data, data["data"])

for key, value in data["data"]["attributes"].items():
for key, value in data["data"].get("attributes", {}).items():
if key not in collection.schema["fields"]:
raise JsonApiDeserializerException(f"Field {key} doesn't exists in collection {collection.name}.")
ret[key] = self._deserialize_value(value, cast(Column, collection.schema["fields"][key]))
Expand Down
18 changes: 18 additions & 0 deletions src/agent_toolkit/tests/services/serializers/test_jsonapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,24 @@ def test_should_correctly_load_one_to_one_relation(self):
},
)

def test_should_work_if_attribute_not_present(self):
deserializer = JsonApiDeserializer(self.datasource)

request_body = {
"data": {
"id": "43661dae-97c3-4ea9-bd43-a6d8ac3f4ca7",
"type": "Orders",
"relationships": {"customer": {"data": {"id": "12", "type": "Persons"}}},
}
}
data = deserializer.deserialize(request_body, self.collection_order)
self.assertEqual(
data,
{
"customer": 12,
},
)


class TestJsonApiSerializer(TestJsonApi):
@classmethod
Expand Down
Loading