Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contentful::Link rather than Contentful::Asset Cached object #110

Closed
niquepa opened this issue May 17, 2018 · 7 comments
Closed

Contentful::Link rather than Contentful::Asset Cached object #110

niquepa opened this issue May 17, 2018 · 7 comments

Comments

@niquepa
Copy link

niquepa commented May 17, 2018

I have the following code to get some entries from contentful:

@professionals = Web::Dentist.all.params({'order' => 'fields.orden', 'locale' => I18n.locale}).load.items

each entry has a relation to an asset (picture), so I'm accessing it like:

- professionals.each do |dentist|
  = dentist.picture.url

It works without any problem and if you inspect each picture you'll see:

<Web::Dentist[dentist] id='496kcSEqCkAuaGiC8as2a8'>
[<Contentful::Asset id='51sOKzSr7iCAoygq6206ES' url='//images.ctfassets.net/0lo6jhr35aeg/51sOKzSr7iCAoygq6206ES/c4c73b51ed40248e9d5f8b2d3bdcab85/DR.Bedoya-web.jpg'>]

but if I try to cache the response like this:

@professionals = Rails.cache.fetch(:"professionals_#{I18n.locale}", expires_in: ENV['cache_ttl'].to_i) do
  Web::Dentist.all.params({'order' => 'fields.orden', 'locale' => I18n.locale}).load.items
end

and then iterate the entries, only the first item has the relation as Contentful::Asset, the rest of items have Contenful::Link, if you inspect each entry you'll see:

<Web::Dentist[dentist] id='496kcSEqCkAuaGiC8as2a8'>
[<Contentful::Link id='51sOKzSr7iCAoygq6206ES'>]

So it throws an error, again it only happens when you cache the response, I'm using memcached for it.

@niquepa
Copy link
Author

niquepa commented Jun 5, 2018

I have the same Issue reported in contentful.rb contentful/contentful.rb#138

have this issue currently but it only appears when we put a cache on an object. When I receive this object from contentful directly I get an Asset when it's a cache hit I sometimes get an Asset but some other time I get a Link. This is quite apparent because out of a collection of two things one has an image of type Asset while the second has an image of type Link.

@dlitvakb
Copy link
Contributor

Hi @niquepa,

Can you let me know which version of the integration and SDK you are using?

This issue has been fixed almost a year ago. The contentful_model integration has been recently updated to version 1.x which includes all the new updates to the SDKs.

Cheers

@niquepa
Copy link
Author

niquepa commented Jun 13, 2018

Hi @dlitvakb I'm including master branch:

gem 'contentful_model', :git => 'https://github.com/contentful/contentful_model.git', :branch => 'master'

checking the Gemfile.lock seems like I'm using v0.2.0:

  remote: https://github.com/contentful/contentful_model.git
  revision: 660bf1bbd499387a04c25e1f6fdbf8f0000c2beb
  branch: master
  specs:
    contentful_model (0.2.0)
      activesupport
      contentful (~> 2.0)
      contentful-management (~> 1.0)
      redcarpet

Should I use v1.0.0 ?

@dlitvakb
Copy link
Contributor

Hey @niquepa,

Please try updating to use 1.0.0, as the dependencies listed seem outdated.

Cheers

@niquepa
Copy link
Author

niquepa commented Jun 14, 2018

This is how my Gemfile.lock looks now:

GIT
  remote: https://github.com/contentful/contentful_model.git
  revision: 91b89361d85c310c42eefbf3c08cbbf372dcd3ad
  specs:
    contentful_model (1.0.0)
      activesupport
      contentful (~> 2.7)
      contentful-management (~> 2.0)
      redcarpet

but the error stills present. The way I get the content from contentful is:

    @professionals = Rails.cache.fetch(:"professionals_#{I18n.locale}", expires_in: ENV['cache_ttl'].to_i) do
      Web::Dentist.all.params({'order' => 'fields.orden', 'locale' => I18n.locale}).load.items
    end

Web::Dentist class is just 3 lines of code:

class Web::Dentist < ContentfulModel::Base
  self.content_type_id = "dentist"
end

The weird thing is that the first element always has the proper relation as ContentfulModel::Asset but the other elements have ContentfulModel::Link

          - professionals.each do |dentist|
            .item
              .thumbnail
                - if !dentist.fotos.blank? && dentist.fotos.first
                  %img{:alt => "", :src => dentist.fotos.first.try(:url)}/

As you can see in the below images, that happens for all the relations, the specialty is not loaded either:

contentful2
contentful1

Thanks for your help

@dlitvakb
Copy link
Contributor

Hey @niquepa,

Can you create a support request here https://support.contentful.com requesting for me and provide me your Space ID and CDA Token? This looks like a possible bug, but I cannot know for sure unless I test it further.

Cheers

@niquepa
Copy link
Author

niquepa commented Jun 14, 2018

@dlitvakb Done:

Ticket 27777

thanks.

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

No branches or pull requests

2 participants