ember.js icon indicating copy to clipboard operation
ember.js copied to clipboard

Converting circular structure to JSON

Open imanny10 opened this issue 2 years ago • 10 comments

I'm trying to add object( which has model) in storage . Getting this error TypeError: Converting circular structure to JSON --> starting at object with constructor 'Store' | property 'recordArrayManager' -> object with constructor 'RecordArrayManager' --- property 'store' closes the circle at JSON.stringify () at Storage.addFavorite (xy-chart-favs.js:43:1) at XYChartController.addXYFavourite (controller.js:573:1) at FavoritesStorage.addFavorite (favorites-storage.js:107:1)

    
     let favObj = {
      name: name,
      card: favorite,
      kpis: favorite.get('kpis').toArray(),
      fromDate: fromDate,
      toDate: toDate,
      isSVS: isSVS,
      siteId: siteId,
      plantId: plantId,
      unitId: unitId,
      aeicId: aeicId,
    };

    let cardObj = JSON.parse(JSON.stringify(favObj));
    const userFavorites = this._userObject(userId);
    userFavorites.favorites.addObject(cardObj);
 I'm deep cloning the object before pushing in storage array to avoid object reference which duplicates the nested object for new object.
 
 It was working in version 3.24 but after upgradation 4.8 (ember cli) not working

imanny10 avatar Apr 26 '23 07:04 imanny10

Same here :-(

bmaehr avatar Oct 08 '24 19:10 bmaehr

Can you provide more information?

  • ember-cli version?
  • ember-source version?
  • stack?
  • error?
  • node version?
  • package manager (and version?)

NullVoxPopuli avatar Oct 08 '24 19:10 NullVoxPopuli

Sure. It is unfortunately not a trivial setup because of ember-data-fragments

ember-cli version: 4.8.0 ember-source version: 4.8.6 node version: v16.19.0 yarn version: 1.22.19 ember-data: 4.6.4 ember-data-model-fragments: 6.0.3

Error while processing route: tracking.index Converting circular structure to JSON
    --> starting at object with constructor 'Store'
    |     property 'recordArrayManager' -> object with constructor 'RecordArrayManager'
    --- property 'store' closes the circle TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Store'
    |     property 'recordArrayManager' -> object with constructor 'RecordArrayManager'
    --- property 'store' closes the circle
    at JSON.stringify (<anonymous>)
    at Class.persist (https://pubx.local/assets/vendor.js:227865:19)
    at Class.persist (https://pubx.local/assets/vendor.js:227363:33)
    at Proxy._updateStore (https://pubx.local/assets/vendor.js:226357:25)
    at Proxy.setUnknownProperty (https://pubx.local/assets/vendor.js:226346:14)
    at Proxy.superWrapper (https

The json looks like this

{
    "data": [
        {
            "id": "803aa7cbd1fa4fd4945457995d9bdfe1",
            "type": "userDetails",
            "links": {
                "self": "/jsonapi/userDetails/803aa7cbd1fa4fd4945457995d9bdfe1"
            },
            "attributes": {
                "active": true,
                "username": "me",
                "firstName": "m",
                "lastName": "e",
                "email": "[email protected]",
                "authorities": [
                    "ROLE_GLOBAL_ADMIN",
                    "ROLE_GLOBAL_LOGIN_FTP",
                    "ROLE_GLOBAL_LOGIN_WEB",
                    "ROLE_GLOBAL_LOGIN_WEBSERVICE",
                    "ROLE_GLOBAL_MB_MANAGER",
                    "ROLE_GLOBAL_REPORTING_MANAGER",
                    "ROLE_GLOBAL_SYSTEM_MANAGER",
                    "ROLE_GLOBAL_TRANSACION_MANAGER",
                    "ROLE_USER"
                ],
                "mbId": null,
                "mbName": null,
                "mbAuthorized": [],
                "mbCrmConnected": null
            }
        }
    ],
    "links": {
        "first": "/jsonapi/userDetails?page[number]=1&page[size]=10000",
        "last": "/jsonapi/userDetails?page[number]=1&page[size]=10000",
        "self": "/jsonapi/userDetails?reload=true"
    },
    "meta": {
        "totalResourceCount": 1
    }
}

The problem happens now while we started to migrate our big project from Ember 2.18 (there it is no problem) to a newer Ember

bmaehr avatar Oct 08 '24 23:10 bmaehr

@runspired what's the migration off ember-data-fragments?

NullVoxPopuli avatar Oct 08 '24 23:10 NullVoxPopuli

there is no migration path currently ready for 5.x: latest version we support it is 4.6 though we are nearing the release of 5.4 which will have support for a replacement paradigm we will then build a migration path to.

runspired avatar Oct 09 '24 00:10 runspired

@runspired what's the migration off ember-data-fragments?

For us making the application work without fragments would be a rewrite of the whole application and we then would switch to an other framework.

there is no migration path currently ready for 5.x: latest version we support it is 4.6 though we are nearing the release of 5.4 which will have support for a replacement paradigm we will then build a migration path to.

You are talking about ember-data 5.4? Do you have any link to what is planed?

bmaehr avatar Oct 09 '24 05:10 bmaehr

No improvement on ember-data: 4.6.6 ember-data-model-fragments: 6.0.10

bmaehr avatar Oct 09 '24 09:10 bmaehr

Good news for me: The issue was cased by an old (4.2.2) version of ember-simple-auth

bmaehr avatar Oct 09 '24 09:10 bmaehr

I have narrend it down. It happens, because we try to store an Ember model into the session of ember-simple-auth. It is ok to save an EmberObject there but not an Ember model.

Any idea how it is possible to "reduce" an EmberModel to an EmberObject?

bmaehr avatar Oct 09 '24 15:10 bmaehr

you'd want to implement a toJSON method on the model, doesn't need to be an EmberObject (you probably don't want it to be an EmberObject)

runspired avatar Oct 16 '24 22:10 runspired