contentful-management.rb icon indicating copy to clipboard operation
contentful-management.rb copied to clipboard

Gem blows up when querying entries that have tags associated with them

Open joelip opened this issue 4 years ago • 4 comments

We recently started experimenting with tags in Contentful and we've found that it breaks a lot of functionality with the Management API. When querying an entry with a tag here is an example object that breaks:

{"metadata"=>{"tags"=>[{"sys"=>{"type"=>"Link", "linkType"=>"Tag", "id"=>"campaignBrand"}}]},
 "sys"=>
  {"space"=>{"sys"=>{"type"=>"Link", "linkType"=>"Space", "id"=>"id"}},
   "id"=>"55FkOYPSmltCpZPgXZiwoY",
   "type"=>"Entry",
   "createdAt"=>"2020-07-31T20:28:35.447Z",
   "updatedAt"=>"2020-11-03T01:24:25.437Z",
   "environment"=>{"sys"=>{"id"=>"legacy-master", "type"=>"Link", "linkType"=>"Environment"}},
   "publishedVersion"=>84,
   "publishedAt"=>"2020-11-03T01:24:25.437Z",
   "firstPublishedAt"=>"2020-08-21T23:51:00.860Z",
   "createdBy"=>{"sys"=>{"type"=>"Link", "linkType"=>"User", "id"=>"4oBuurbO6ICl4oibcibtkg"}},
   "updatedBy"=>{"sys"=>{"type"=>"Link", "linkType"=>"User", "id"=>"4oBuurbO6ICl4oibcibtkg"}},
   "publishedCounter"=>6,
   "version"=>85,
   "publishedBy"=>{"sys"=>{"type"=>"Link", "linkType"=>"User", "id"=>"4oBuurbO6ICl4oibcibtkg"}},
   "contentType"=>{"sys"=>{"type"=>"Link", "linkType"=>"ContentType", "id"=>"productPage"}}},
 "fields"=>
  {"slug"=>{"en"=>"why-square-2"},
   "metadata"=>{"en"=>{"sys"=>{"type"=>"Link", "linkType"=>"Entry", "id"=>"251HdGEynHSJ03hvgjgnxF"}}},
   "locales"=>{"en"=>["US"]},
   "sections"=>
    {"en"=>
      [{"sys"=>{"type"=>"Link", "linkType"=>"Entry", "id"=>"4z5cgXD4B9OQjDdngPNstK"}},
       {"sys"=>{"type"=>"Link", "linkType"=>"Entry", "id"=>"uk8aHThRReCfrdRDKoeYu"}},
       {"sys"=>{"type"=>"Link", "linkType"=>"Entry", "id"=>"3f9GUXvkQZD96BRaCxGHPo"}},
       {"sys"=>{"type"=>"Link", "linkType"=>"Entry", "id"=>"3hdf2gHipyTlzMznX7bo1Y"}},
       {"sys"=>{"type"=>"Link", "linkType"=>"Entry", "id"=>"QSnggXyICvZMn181E6pDO"}},
       {"sys"=>{"type"=>"Link", "linkType"=>"Entry", "id"=>"CpqsmycoDdnVkaSHFvkm7"}},
       {"sys"=>{"type"=>"Link", "linkType"=>"Entry", "id"=>"6umcmNdrXQoKaWhp2zw1Ef"}},
       {"sys"=>{"type"=>"Link", "linkType"=>"Entry", "id"=>"7e0qhknUVUEYcAgCAcaAgc"}},
       {"sys"=>{"type"=>"Link", "linkType"=>"Entry", "id"=>"2DjDt3oqMJUmQgjES4QbuX"}},
       {"sys"=>{"type"=>"Link", "linkType"=>"Entry", "id"=>"7e0qhknUVUEYcAgCAcaAgc"}},
       {"sys"=>{"type"=>"Link", "linkType"=>"Entry", "id"=>"2Bd7we0VPLWxNRtVdNFj2u"}},
       {"sys"=>{"type"=>"Link", "linkType"=>"Entry", "id"=>"7e0qhknUVUEYcAgCAcaAgc"}},
       {"sys"=>{"type"=>"Link", "linkType"=>"Entry", "id"=>"10lVzbPii7F6AlibXqwH7x"}},
       {"sys"=>{"type"=>"Link", "linkType"=>"Entry", "id"=>"7e0qhknUVUEYcAgCAcaAgc"}},
       {"sys"=>{"type"=>"Link", "linkType"=>"Entry", "id"=>"4Z5yeqV3u1BFcKTz96hVCQ"}},
       {"sys"=>{"type"=>"Link", "linkType"=>"Entry", "id"=>"7e0qhknUVUEYcAgCAcaAgc"}},
       {"sys"=>{"type"=>"Link", "linkType"=>"Entry", "id"=>"N5BS5VKV83O0LOsCDX5eV"}}]},
   "navigationBannerColor"=>{"en"=>"white"},
   "stylesheets"=>{"en"=>[{"sys"=>{"type"=>"Link", "linkType"=>"Entry", "id"=>"1L0WLp4fxMP39paRW3IUuh"}}]},
   "javascripts"=>{"en"=>[{"sys"=>{"type"=>"Link", "linkType"=>"Entry", "id"=>"2ODnsqoZ5l4RxXHw8BNqZe"}}]},
   "translationState"=>{"en"=>"not_needed"},
   "translationOptions"=>{"en"=>{"contact_email"=>"[email protected]", "included_fields"=>[], "required_locales"=>[], "translations_required"=>true}},
   "translationProgress"=>{"en"=>{"watchers"=>[]}},
   "displayType"=>{"en"=>true}}}

It blows up on this line in the replace_children method. I'm not sure what the underlying problem is here, but I'm afraid that it's a name conflict between metadata (the tags object) and metadata our Entry field. If not, then it might just be that the gem doesn't support tags in general yet.

Any help on fixing this would be very helpful. Thanks.

joelip avatar Jan 05 '21 23:01 joelip

I'm happy to create a PR to update this next condition to also skip "metadata" but I'm not sure if you want to actually support the resource more fully.

joelip avatar Jan 05 '21 23:01 joelip

@dlitvakb hey, thanks for merging that PR. However, it looks like you didn't really address this part of my issue:

I'm afraid that it's a name conflict between metadata (the tags object) and metadata our Entry field.

We have literally thousands of entries that have an associated metadata field. Is there any way to fix that issue too? The metaprogramming in the gem makes it difficult to work around this.

joelip avatar Jan 07 '21 18:01 joelip

Hey @joelip ,

To access the field, you can always use the entry.fields(locale)[:field_name] accessor if there's any conflict.

Cheers

dlitvakb avatar Jan 08 '21 11:01 dlitvakb

@joelip thanks for reporting the issue.

The SDK doesn't support content tags yet. I am working on adding support for content tags and fix name conflict issue.

Cheers

rubydog avatar Feb 06 '21 05:02 rubydog