question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Circular references wheen include is >= 2

See original GitHub issue

When setting a getEntries with an include of 2, I’m still getting circular references and being unable to JSON.stringify it. In addition, toPlainObject does nothing, and stringifySafe just blocks forever.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

16reactions
Mk-Etlingercommented, Jun 7, 2019

@cachrisman Hey thanks for your reply! I’m sending my response as JSON to the client to consume and therefore it’s stringify’d.

because you have a circular reference where level 1 is referring to level 2 which is referring to level 1, the SDK, by default, will traverse the tree forever.

I actually have a circular reference on the 5th level deep. This is why I only want to include 4 levels deep and not resolve past that. So I would want the links to resolve down to the 4th level, the 5th being a of { type: 'link'}

The hierarchy is like this:

Countries -> Homepage -> Categories -> Sub Categories -> Asset Wrappers(this has the exclusiveCountry field which refs Countries)

This is starting to make sense though, and I see your point(in this case I actually might need to include 5 levels, but let’s keep it 4 for consistency sake).

This is probably a feature rather than a bug. Let me see if I’m understanding correctly.

const client = contentful.createClient({
    space: '<space_id>', 
    accessToken: '<access_token>', 
    resolveLinks: false
})

The above doesn’t resolve any links at all, so you end up with { type: 'link'} as properties instead of the associated Content Type object.

I’m looking for something like this:

const entries = await client.getEntries({
      'sys.id': countryId,
      include: 4,
      resolveLinksDepth: 4
    });

Expected Behavior:

Resolve all of the links up until the 4th level which is specified by the include parameter but do not resolve past that. So the 5th is a { type: 'link'} which avoids the circular ref.

Current Behavior:

If resolveLInks is on, all links will be resolved that are included in the response, even if that includes circular JSON. Include doesn’t have any effect on which links are resolved.

Do I have that right? How feasible would this be?

From my perspective, if you don’t want to include past a certain level, why would you want to resolveLinks past that level?

Let me know if the above makes sense or if you need any more info.

Thanks!

4reactions
Mk-Etlingercommented, Jun 7, 2019

There’s definitely a bug happening somewhere. Can we re-open this?

I’m currently using the Node Client(“contentful”: “^7.1.0”, node -v: v10.12.0) and getting the following error:

TypeError: Converting circular structure to JSON

I have a Asset Wrapper content-type which has a field called exclusiveCountries which refs Countries. So assetWrappers(CT): exclusiveCountries(field) -> Countries(CT, this will eventually reference assetWrappers)

My query looks like this:

const entries = await client.getEntries({
      'sys.id': countryId,
      include: 4,
    });

I need exactly 4 levels of links resolved and nothing more. However, on the 4th level of content the links are still being resolved all the way down the hierarchy.

Expected behavior:

include parameter actually limits the links resolved to 4, even on a linked, references many content-type. I’m assuming that it’s also including 4 levels deep on that, which is throwing this error.

Happy to provide more info but trying to get the ball rolling again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove or allow a circular reference - Microsoft Support
Find and remove a circular reference. You can also learn about the circular reference warning message and iterative calculation in Excel.
Read more >
Circular reference in Excel: how to find, enable, use, or remove
Learn the basics of Excel circular reference - how to check workbooks for circular formulas, and how to enable, find and remove circular ......
Read more >
What Is Circular Reference in Excel? Everything You Need to ...
Circular reference is a type of error in Excel that occurs when a formula in a cell tries to calculate itself. Find out...
Read more >
Circular reference - Wikipedia
A circular reference is a series of references where the last object references the first, resulting in a closed loop. Circular reference (in...
Read more >
How to Find and Fix Circular References in Excel
A circular reference occurs when you end up having a formula in a cell – which in itself uses the cell reference (in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found