Skip to content

Conversation

@jkeuleya
Copy link

Issue:

When we have a deserializer with a references_many inside and that we don't receive this value in the response of the API call, it crashes.

What we want:

When we have a deserializer with a references_many inside and that we don't receive this value in the response of the API call, it should just ignore it and continue reading next attributes as it works for references_one and attribute.

What's happening concretely in the code:

While deserializing, while arriving on a non existing reference_many in the response, we .assign_attribute the reference_many with a nil value. This causes the crash (lib/ledger_sync/deserializer.rb:44).

What's the plan:

Maybe try to set the value to [] (empty array) when the reference is not present in the response.

Example:

Screenshot from 2024-08-31 15-20-22
Screenshot from 2024-08-31 15-20-59

When I receive the answer from my API call on AmazonBusinessAPI, sometimes, it doesn't have the "packages" key with an array as value, like that:

# Response from API with `packages`
deserializer = AmazonBusinessApi::AcceptanceArtifact::Deserializer.new
response = { "identifier" => "42", "packages" => [] }
accept_art = deserializer.deserialize(hash: response, resource: AmazonBusinessApi::AcceptanceArtifact.new)
=> Success

# Response from API call without `packages`
deserializer = AmazonBusinessApi::AcceptanceArtifact::Deserializer.new
response = { "identifier" => "42" }
accept_art = deserializer.deserialize(hash: response, resource: AmazonBusinessApi::AcceptanceArtifact.new)
=> .../ledger_sync/lib/ledger_sync/error/resource_errors.rb:23:in `generate_message': undefined method `reject' for nil:NilClass (NoMethodError)
=> invalid_classes = value.reject { |e| e.is_a?(type_resource_class) }.map(&:class)

In the first case, everything works fine. In the second case, the gem searches for packages, doesn't find it and crashes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant