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

"Maximum call stack size exceeded" on circular-references #194

Closed
mrsteele opened this issue Oct 23, 2017 · 18 comments
Closed

"Maximum call stack size exceeded" on circular-references #194

mrsteele opened this issue Oct 23, 2017 · 18 comments
Assignees
Labels

Comments

@mrsteele
Copy link

mrsteele commented Oct 23, 2017

  • Node Version: v8.0.0
  • Npm Version: v5.4.2
  • Platform: Darwin Kernel Version 17.0.0: Thu Aug 24 21:48:19 PDT 2017; root:xnu-4570.1.46~2/RELEASE_X86_64 x86_64 (its a macbook pro on osx 10.13)
  • Package Version: v5.0.1

Our contentpull package (https://github.com/remedyhealth/contentpull) wraps this package to simplify some of our conventional queries. We were alerted that our tests were failing when upgrading to your latest (v5.0.1).

It was discovered after using this package on its own that our test data was failing due to a maximum call stack issue (as seen below)

RangeError: Maximum call stack size exceeded
      at memoized (node_modules/contentful/dist/webpack:/node_modules/lodash/memoize.js:54:1)
      at Object.get (node_modules/contentful/dist/webpack:/mixins/link-getters.js:61:20)
      at node_modules/contentful/dist/webpack:/mixins/link-getters.js:42:21
      ...

Our failure is a circular referential test. While this is a bit odd we do have this circumstance in production (related categories reference each other).

Our test is simply to make sure those references work (which worked fine in previous versions):

it('should be able to parse a circularly referenced object', () => {
  return client.getEntries({'sys.id': entryId}).then(entries => {
  let nested = entries.items[0].fields.ref.fieds.ref.fields.ref.fields.ref.fields.ref // you get the idea...
  nested.sys.id.should.equal(entryId)
})

Our test data is a single reference to itself on the field ref. Below you will find the sample data:

{
  sys: {
    space: {
      sys: {
        type: 'Link',
        linkType: 'Space',
        id: 'space1'
      }
    },
    id: 'entry1',
    type: 'Entry',
    createdAt: '2016-04-06T15:43:38.945Z',
    updatedAt: '2016-06-08T14:52:24.824Z',
    revision: 4,
    contentType: {
      sys: {
        type: 'Link',
        linkType: 'ContentType',
        id: 'contentType1'
      }
    },
    locale: 'en-US'
  },
  fields: {
    title: 'TestEntry',
    ref: {
      sys: {
        type: 'Link',
        linkType: 'Entry',
        id: 'entry1'
      }
    }
  }
}

Please let us know if there is anything else we can assist with in resolving this issue.

@Khaledgarbaya
Copy link
Contributor

hi @mrsteele ,
Let me check that and get back to you asap

Khaled

@mrsteele
Copy link
Author

Just an FYI This issue appears to exist in any version greater than 4.6.2.

@axe312ger
Copy link
Collaborator

i will have a look 👀

@stijlfigurant
Copy link

Also experiencing this issue

@Khaledgarbaya
Copy link
Contributor

This issue should be fixed now in the @next release. more infos here.
Can you check with the version mentioned the above link?

Best,
Khaled

axe312ger pushed a commit that referenced this issue Jan 9, 2018
@axe312ger
Copy link
Collaborator

We released another beta release to address this issue. Feedback is very welcome :)

Install via npm install contentful@next

@mrsteele
Copy link
Author

mrsteele commented Jan 9, 2018

Thanks @axe312ger! I can confirm installing this locally resolved our maximum call stack issue!

Thanks so much and we will be looking forward to the next official release of this!

@stijlfigurant
Copy link

stijlfigurant commented Jan 10, 2018

I am still experiencing this issue with the new version, but I think my usecase is different.

I have a content-type blogPost, which can have 3 related blogPosts (references, many). Simplified, something like this happens:

blogPost A, has blogPost X, Y and Z as related blogPosts
in turn, blogPost X has blogPost A as related blogPost

So the circular dependency lies one level deeper.

With resolveLinks: false it wont fail, but then I will still need manually resolve the links. With resolveLinks: true and include: 1 it will still throw RangeError: Maximum call stack size exceeded

@axe312ger
Copy link
Collaborator

@stijlfigurant are you sure you are using the beta version via npm install contentful@next?

We have a test checking for a similar structure and it is not exceeding the call stack. (https://github.com/contentful/contentful-resolve-response/blob/master/test/unit/index-test.js#L137-L170)

@stijlfigurant
Copy link

stijlfigurant commented Jan 10, 2018

  "_from": "contentful@next",
  "_id": "[email protected]",

in node_modules/contentful/package.json

@axe312ger
Copy link
Collaborator

Alright, we will investigate. Thank you @stijlfigurant

@axe312ger
Copy link
Collaborator

axe312ger commented Jan 10, 2018

Hey @stijlfigurant,

I added the following test which should imitate your data structure. It runs through smoothly and does not cause any issues.

https://github.com/contentful/contentful-resolve-response/pull/11/files#diff-3231241b8213a16d3240ad710704bb6d

Can you please check if this matches your data structure?

If yes, we might need to switch to our support software where you might give me access to your space so I can have a deeper look by using access tokens for your space and replicating the issue on my machine with exactly your data. (https://www.contentful.com/support/ + link this issue to make sure it ends up on my desk :) )

Thanks a lot,
Benedikt

@stijlfigurant
Copy link

stijlfigurant commented Jan 10, 2018

@axe312ger The data structure looks similar, but I am guessing where it goes wrong is when it returns another entry, it also returns another linkField with it which doesn't seem to reflect in the test. E.g.

{
          sys: { type: 'Entry', locale: 'en-US', id: 'A' },
          fields: {
            linkfield: [
              { sys: { type: 'Link', linkType: 'Entry', id: 'X', fields: { linkField: [ sys: { type: 'Entry', locale: 'en-US', id: 'A' }, fields: { linkField: [ FURTHERRECURSION... ] } ] } },
              { sys: { type: 'Link', linkType: 'Entry', id: 'Y' } },
              { sys: { type: 'Link', linkType: 'Entry', id: 'Z' } }
            ]
          } 
}

happy to give you access to our space so you can reproduce :)

@centrical
Copy link

centrical commented Jul 6, 2018

Stilll having this issue. I tried to upgrade to Contentful @next, but that didn't work either.

Situation: my space has articles and posts. Article A has a multiple reference field with "related posts" that includes Post B. Post B has a multiple reference field with "related articles", that includes Article A. It is easy to reproduce: if I remove the circular reference, the error is gone - if I add it again, it's there.

I really need this feature, because support articles often refer to either other articles or to blog posts, and vice versa. What to do?

UPDATE: I found out that the bug sits in another tool, "contentful-to-algolia", which syncs data from CF to Algolia search. I will file an issue there. Sorry for any inconvenience!

@patriciomase
Copy link

this keeps happening. Same case of blogpost linking to 3 blogposts. If it links to itself RangeError: Maximum call stack size exceeded shows up

@dndrsn
Copy link

dndrsn commented Nov 4, 2020

Experiencing the same issue. A thing that is related to a thing that is related back to it. Not an uncommon scenario. Using 7.14.8. Is there any known workaround?

@robertsoniv
Copy link

I am experiencing this issue using version ^8.1.4. Have a content type that references many of it's own content type, each of which can also reference many. Using the method parseEntries after getting all entries of said content_type (limit 1000).

@axe312ger
Copy link
Collaborator

@matthew-contentful @TimBeyer I guess you should consider reopening this as people seem to still run into this issue

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

Successfully merging a pull request may close this issue.

7 participants