contentful.rb: Bug in hydration with circular references?
Hello!
I think I may have found a pretty subtle bug in the “hydration” code, which has taken me a long time to drill down to now X) Let me explain the setup:
Among other content_types, we have so called “Winner” and “News” (also called Articles) entries. News have a rich_text field that has elaborate text and inline images. A winner can link to many news, and sometimes news in turn link to Winners. This is usually no problem, but in a specific call we get a single winner with include 2, which sometimes means that there are news which have the same winner on it again. If that happens, everything looks fine at first, but some of the images (assets) in rich_image entries in rich_text of the news will not be hydrated, crashing our rendering, as it expects to get the urls of assets directly, but will encounter Link objects.
What’s making this more head-scratching is that this only occurs when the news of the winner are in a specific order - when re-ordered, the hydration works, even though no other data is changed (I’m attaching two samples, they are the different orders of the same winner-with-two-news, and also the content types of news and winners).
This also doesn’t occur when setting reuse_entries to true.
Also, the include option on the call, or max_include_resolution_depth have no effect on the hydration issue (i.e. I tried it with much higher values than 2/4, and it has no effect).
Here’s more info, let me know if there is more needed:
gem version 2.15.3
relevant settings:
{
entry_mapping: {
'news' => Content::News::Article,
'author' => Content::News::Author,
'category' => Content::News::Category,
'milestone' => Content::News::Highlight,
'jobs' => Content::News::Job,
'pages' => Content::News::Page,
'press_release' => Content::News::PressRelease,
'member' => Content::News::TeamMember,
'media_coverage_item' => Content::News::MediaCoverageItem,
'profile_message_to_all_users' => Content::News::UserMessage,
'simple_data_record' => Content::News::SimpleDataRecord,
'winner' => Content::News::Winner,
'ad_hoc_campaign' => Content::AdHoc::Campaign,
'notification' => Content::AdHoc::Notification,
'rich_image' => Content::News::Elements::RichImage,
'button' => Content::News::Elements::Button,
'youtube_video' => Content::News::Elements::YoutubeVideo,
'html_code' => Content::News::Elements::HtmlCode,
'pilot_member' => Content::Pilot::TeamMember
},
reuse_entries: false,
dynamic_entries: :auto,
max_include_resolution_depth: 4,
raise_for_empty_fields: false,
}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (9 by maintainers)
@floriank thanks for staying on it, and also for the new release, I’m working on integrating it and removing our hacks 😃
I successfully build a version that fails like your response: See https://github.com/floriank/contentful.rb/blob/fix/issue-225/spec/entry_spec.rb#L788.
Turns out this behaviour is at least odd. Paging @dlitvakb for visibility.
@floriank We’re doing this:
@floriank Hmm no idea where that got lost, sorry. Can you try again, please?
@floriank Ah yes, my bad. Thanks for looking at this, much appreciated!