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

stack too deep issue updating a model with a linked field #76

Closed
niedfelj opened this issue Sep 6, 2017 · 7 comments
Closed

stack too deep issue updating a model with a linked field #76

niedfelj opened this issue Sep 6, 2017 · 7 comments
Assignees
Labels

Comments

@niedfelj
Copy link

niedfelj commented Sep 6, 2017

I'm running into a strange issue where saving an object with a linked field is generating a stack too deep issue. I've created a demo app here that you can use to test/debug:

https://github.com/niedfelj/contentful_model_bug

It seems to get stuck in the as_json call of a model class, recursively calling as_json on the class over and over because when it calls instance_values on a class, another reference to the class is returned which then also has as_json called on it which of course returns the same hash of instance_values

@dlitvakb
Copy link
Contributor

dlitvakb commented Sep 7, 2017

Hey @niedfelj,

This is a known issue with the 0.x and 1.x versions of the CDA SDK. I'm working on the 1.0 release of this gem which uses the 2.x version of the CDA SDK, which has this fixed and is configurable for how deep you want nesting resolutions.

I don't have an ETA for when this will be finally released, but most likely within the next 2 months.

In the meantime, feel free to use master and if you can provide feedback regarding the next version it will be much appreciated.

Cheers

@dlitvakb dlitvakb self-assigned this Sep 7, 2017
@niedfelj
Copy link
Author

niedfelj commented Sep 7, 2017

Hi David, Are you sure this is the same issue? I don't really have cyclical relationships in my data, so it feels like it's something else?

@dlitvakb
Copy link
Contributor

dlitvakb commented Sep 7, 2017

Oh, I understood the issue incorrectly then.

Can you please let me know if you add the code indicated here in an initializer if the issue is fixed?
contentful/contentful-management.rb#87 for the management gem and the following equivalent snippet for the delivery gem:

module Contentful
  class Entry
    alias_method :to_json, :raw_with_links
  end
end

Please let me know if that solves your issue, so that I can update this gem accordingly.

Cheers

@niedfelj
Copy link
Author

niedfelj commented Sep 7, 2017

On first try, that doesn't seem to resolve the issue either. I will see if I can get a 2.x version of CDA working later today and let you know?

@niedfelj
Copy link
Author

niedfelj commented Sep 7, 2017

Did you have a chance to look at my demo of the bug?

@dlitvakb
Copy link
Contributor

dlitvakb commented Sep 7, 2017

Hey @niedfelj,

I haven't had the time today yet. But either tomorrow or Monday, I'll definitely take a look into it.

I pointed you towards that issue on the CMA SDK, because I had at least something similar happen (by the looks of my issue description and yours) and that was the way I got it solved.

As soon as I find a way to solve it, I'll let you know.

Cheers

@dlitvakb
Copy link
Contributor

Hey @niedfelj,

Found what I think the issue is.

It looks like the has_one relationship is not properly defining setter methods.

This ends up making setting the section or author field in your articles not work by using the shortcut section= or author= methods.

I found it possible to go through this issue by using the internal #to_management method and creating the link hash manually like this:

mgmt_article = article.to_management
mgmt_article.section = {sys: {id: section.id, type: 'Link', linkType: 'Entry'}}
mgmt_article.save
mgmt_article.publish

article = Contentful::Article.find(mgmt_article.id)
article.section
# => <Contentful::Section[section] id='6KSRtnjHfGueIIuE2aiWco'>

I'll add this as a bug in our backlog, I'm currently working on finalizing a release for the CMA SDK, as soon as I'm done with that, I'll be back on working on the new release of this gem, which will have a fix for this bug included.

On the meantime, I please ask you to use this workaround on has_one relationships.

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants