Skip to content

Commit

Permalink
Fix marshal load of array for drafted/deleted child entries
Browse files Browse the repository at this point in the history
The current behaviour for deleted/drafted entries it's different for retrieved and unserialized arrays.

Let's suppose I have a model with some reference array field. And let's suppose I have a published entry with some unpublished entries on that referenced on that field.
This is the current behaviour for requested arrays:
```ruby
entries = client.entries(some_query)
# => <Contentful::Array total=1 skip=0 limit=100>
entries.first.raw['fields']['children']
# => [{"sys"=>{"type"=>"Link", "linkType"=>"Entry", "id"=>"6ZEkh78aryxwWinQhB2MNq"}}]
entries.first.children
# => []
```
That is the right and expected behaviour, ignoring drafted entries. However, if we do the same after serializing and unserializing the array:
```ruby
Marshal.load(Marshal.dump(entries)).first.children
# => [<Contentful::Link id='6ZEkh78aryxwWinQhB2MNq'>]
```

This fix should solve that issue by sending the errors to the ResourceBuilder
  • Loading branch information
HQ063 authored Sep 12, 2019
1 parent 9421898 commit e462c13
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/contentful/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def marshal_load(raw_object)
ResourceBuilder.new(
item.raw,
raw_object[:configuration].merge(includes_for_single: Support.includes_from_response(raw, false)),
item.respond_to?(:localized) ? item.localized : false
item.respond_to?(:localized) ? item.localized : false,
0,
raw_object[:configuration][:errors]
).run
end
end
Expand Down

0 comments on commit e462c13

Please sign in to comment.