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.

Ember.Object with ownerInjection cannot be JSON.stringified

See original GitHub issue

Hi!

I ran into an issue (offirgolan/ember-cp-validations#507) while introducing ember-cp-validations into a project where creating Ember.Objects with an ownerInjection results in TypeError: Converting circular structure to JSON. I have provided an Ember Twiddle https://ember-twiddle.com/979d8fc762574b457e04393cd9852159?openFiles=controllers.index.js%2C that demonstrates this behavior.

As the default Ember Data ajaxOptions function calls JSON.stringify, I overrode this function in my app to ignore the __OWNER__ property.

I don’t know that addressing the circular reference makes sense in this context as the entire instance would then appear in the stringified representation so perhaps Ember Data is the correct repo to report this in? If that is the case, please let me know and I’ll close this in favor of an issue in the Ember Data repo. Thanks 😃

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
vincent99commented, Sep 28, 2018

I mean we just use the hackaround as I described above in our product, but it is still an issue… All you really need to reproduce it is:

    var cycle = Ember.Object.create();
    cycle.set('cycle', cycle);
  
    var x = Ember.Object.create();
    Ember.setOwner(x, cycle);
    
    try {
      JSON.stringify(x);
    } catch (e) {
     alert(e);
    }

Here’s a twiddle of the same: https://ember-twiddle.com/b11d1084021dd0ff1dcf19226f2d7d01

And the fix would be to have setOwner() define it as a non-enumerable property as I did above.

1reaction
rynam0commented, Apr 20, 2020

Confirmed. I was able to delete my overridden ajaxOptions function. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set model not consoled by JSON stringify - what is wrong?
I am setting some value to model like : afterModel:function(model,transation){ Ember.set(model, 'processedTrans', 'TechMahindra'); },.
Read more >
EngineInstance - 4.8 - Ember API Documentation
The sender is the object that changed. The key is the property that changes. The value property is currently reserved and unused. The...
Read more >
ember-source | Yarn - Package Manager
Ember.js is a JavaScript framework that greatly reduces the time, effort and resources needed to build any web application. It is focused on...
Read more >
ember-signature-pad - npm
Start using ember-signature-pad in your project by running `npm i ember-signature-pad`. ... return JSON.stringify(this.get('signature'));.
Read more >
ember-source @ 3.8.1 .. 3.10.0 - Package Diff
templateFactory)(json)); ... If you don't, Ember may not have an opportunity to ... _debug.assert)("You passed in `" + JSON.stringify(value) + "` as the ......
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