Collections - Unable to preview collection items due to serialization issues

Feature(s) impacted

Collections

Observed behavior

  • Click on a parent collection
  • Click on an item within that collection
  • Forestadmin crashes with the following message "Your server encountered an error
    Please check your server logs for more information. If the error persists, please let us know ."

Expected behavior

Clicking on a child item from a parent collection should navigate to the child collection details screen.

Failure Logs

2022-10-07T08:50:36.564767+00:00 app[web.1]: e[31m[forest] 🌳🌳🌳  Unexpected error: opts.attributes.filter is not a functione[39m
2022-10-07T08:50:36.564769+00:00 app[web.1]: e[31m{e[39m
2022-10-07T08:50:36.564773+00:00 app[web.1]: e[31m  "stack": "TypeError: opts.attributes.filter is not a function\n    at module.exports.serializeNested (/app/node_modules/jsonapi-serializer/lib/serializer-utils.js:243:32)\n    at module.exports.serialize (/app/node_modules/jsonapi-serializer/lib/serializer-utils.js:182:21)\n    at /app/node_modules/jsonapi-serializer/lib/serializer-utils.js:308:14\n    at arrayEach (/app/node_modules/lodash/_arrayEach.js:15:9)\n    at forEach (/app/node_modules/lodash/forEach.js:38:10)\n    at module.exports.perform (/app/node_modules/jsonapi-serializer/lib/serializer-utils.js:292:5)\n    at resource (/app/node_modules/jsonapi-serializer/lib/serializer.js:35:20)\n    at module.exports.serialize (/app/node_modules/jsonapi-serializer/lib/serializer.js:57:14)\n    at new module.exports (/app/node_modules/jsonapi-serializer/lib/serializer.js:65:17)\n    at /app/node_modules/forest-express/dist/serializers/resource.js:239:14\n    at tryCatcher (/app/node_modules/forest-express/node_modules/bluebird/js/release/util.js:16:23)\n    at Promise._settlePromiseFromHandler (/app/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:547:31)\n    at Promise._settlePromise (/app/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:604:18)\n    at Promise._settlePromise0 (/app/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:649:10)\n    at Promise._settlePromises (/app/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:729:18)\n    at _drainQueueStep (/app/node_modules/forest-express/node_modules/bluebird/js/release/async.js:93:12)\n    at _drainQueue (/app/node_modules/forest-express/node_modules/bluebird/js/release/async.js:86:9)\n    at Async._drainQueues (/app/node_modules/forest-express/node_modules/bluebird/js/release/async.js:102:5)\n    at Immediate.Async.drainQueues [as _onImmediate] (/app/node_modules/forest-express/node_modules/bluebird/js/release/async.js:15:14)\n    at processImmediate (node:internal/timers:466:21)"e[39m
2022-10-07T08:50:36.564773+00:00 app[web.1]: e[31m}e[39m

Context

  • Project name: Jeconteste
  • Team name: Operation
  • Environment name: Production
  • Agent type & version: …
  • Express Version: 4.17.1
  • Database: mongodb
  • Recent changes made on your end if any: imported a new schema made up of json objects

hello @Atuh_Leroi ,

Welcome to the community! Thanks for your feedback. Did you add any custom code in your agent code (smart action, … ) ?

Kind regards,

Florian

@Florian_Gonzales

Hello Florian, hope you’re doing well.

I’m getting the exact same error. It’s a fresh environment with no custom code, or smart action. I’m using a forest-express-mongoose as the backend and the models are generated from the database directly and they are not altered in any way.

A quick exploration in order to isolate the problem made me think this is about nested model serialization. Most models are displayed with no problem but some with nested documents result cause this problem. Apparently, json-serializer expects a proper javascript array in its implementation as part of the “attributes” field of the “opt” parameter, but it doesn’t receieve it.

I’m adding the relevant part of the schema for one of the models with this problem in case that would help you reproduce the problem.

 {
    "name": "prop",
    "nameOld": "prop",
    "icon": null,
    "integration": null,
    "isReadOnly": false,
    "isSearchable": true,
    "isVirtual": false,
    "onlyForRelationships": false,
    "paginationType": "page",
    "fields": [{
      "field": "_id",
      "type": "String",
      "defaultValue": null,
      "enums": null,
      "integration": null,
      "isFilterable": true,
      "isPrimaryKey": true,
      "isReadOnly": false,
      "isRequired": false,
      "isSortable": true,
      "isVirtual": false,
      "reference": null,
      "inverseOf": null,
      "validations": []
    }, {
      "field": "areaId",
      "type": "Number",
      "defaultValue": null,
      "enums": null,
      "integration": null,
      "isFilterable": true,
      "isPrimaryKey": false,
      "isReadOnly": false,
      "isRequired": false,
      "isSortable": true,
      "isVirtual": false,
      "reference": null,
      "inverseOf": null,
      "validations": []
    }, {
      "field": "id",
      "type": "Number",
      "defaultValue": null,
      "enums": null,
      "integration": null,
      "isFilterable": true,
      "isPrimaryKey": false,
      "isReadOnly": false,
      "isRequired": false,
      "isSortable": true,
      "isVirtual": false,
      "reference": null,
      "inverseOf": null,
      "validations": []
    }, {
      "field": "interactable",
      "type": {
        "fields": [{
          "field": "name",
          "type": "String"
        }, {
          "field": "description",
          "type": "String"
        }, {
          "field": "visual",
          "type": {
            "fields": [{
              "field": "color",
              "type": "String"
            }, {
              "field": "asset",
              "type": "String"
            }, {
              "field": "scale",
              "type": "Number"
            }, {
              "field": "x",
              "type": "Number"
            }, {
              "field": "y",
              "type": "Number"
            }, {
              "field": "width",
              "type": "Number"
            }, {
              "field": "height",
              "type": "Number"
            }, {
              "field": "depth",
              "type": "Number"
            }]
          }
        }, {
          "field": "attributes",
          "type": {
            "fields": [{
              "field": "weight",
              "type": "Number"
            }, {
              "field": "hardness",
              "type": "Number"
            }]
          }
        }, {
          "field": "situationalIds",
          "type": ["String"]
        }, {
          "field": "condition",
          "type": ["String"]
        }, {
          "field": "linkedCardId",
          "type": "String"
        }]
      },
      "defaultValue": null,
      "enums": null,
      "integration": null,
      "isFilterable": true,
      "isPrimaryKey": false,
      "isReadOnly": false,
      "isRequired": false,
      "isSortable": true,
      "isVirtual": false,
      "reference": null,
      "inverseOf": null,
      "validations": []
    }],
    "segments": [],
    "actions": []
  }```

seems like, in my case at least, it’s happening because my model has a nested model named “attributes” and it’s causing some confusion for the serializer.

This is the serializationOptions object that’s causing the exception:

{
  id: '_id',
  attributes: [ 'id', 'areaId', 'interactable', '_id' ],
  keyForAttribute: [Function: keyForAttribute],
  typeForAttribute: [Function: typeForAttribute],
  meta: undefined,
  interactable: {
    attributes: { attributes: [Array] },
    visual: { attributes: [Array] }
  }
}

here’s a fix: fix: allow nested models named attributes to be serialized by fakalit · Pull Request #959 · ForestAdmin/forest-express · GitHub

1 Like

Hello @psilocybe ,

Thank you very much for your feedback on this bug! :pray: I managed to reproduce it on my side and the fix should be delivered in a short time (probably tomorrow), I will keep you informed when it’s done ! :+1:

Kind regards,

Florian

2 Likes

Hello @psilocybe,

Sorry for the wait but the fix you contributed to is live ! :rocket: If you still have any problem don’t hesitate to come back to me. :pray: Thanks again for your contribution it helps us a lot!

Kind regards,

Florian

1 Like

@Florian_Gonzales No worries. I really apreciate you guys released a hot fix with it already. Cheers!

1 Like