forest-express-mongoose icon indicating copy to clipboard operation
forest-express-mongoose copied to clipboard

Cannot set property because of object depth

Open bybrunobarros opened this issue 7 years ago • 0 comments

Expected behavior

I should be able to access a collection in ForestAdmin

Actual behavior

I get the message "Oops, something went wrong" when I try to access a collection

Failure Logs

error [forest] 🌳🌳🌳  Unexpected error: Cannot set property 'stats' of null
Cannot set property 'stats' of null
    at /var/app/node_modules/forest-express/dist/serializers/resource.js:60:29
    at arrayMap (/var/app/node_modules/forest-express/node_modules/lodash/lodash.js:614:23)
    at Function.map (/var/app/node_modules/forest-express/node_modules/lodash/lodash.js:8561:14)
    at getAttributesFor (/var/app/node_modules/forest-express/dist/serializers/resource.js:46:9)
    at /var/app/node_modules/forest-express/dist/serializers/resource.js:64:13
    at arrayMap (/var/app/node_modules/forest-express/node_modules/lodash/lodash.js:614:23)
    at Function.map (/var/app/node_modules/forest-express/node_modules/lodash/lodash.js:8561:14)
    at getAttributesFor (/var/app/node_modules/forest-express/dist/serializers/resource.js:46:9)
    at ResourceSerializer.perform (/var/app/node_modules/forest-express/dist/serializers/resource.js:149:5)
    at /var/app/node_modules/forest-express/dist/routes/resources.js:24:140
    at tryCatcher (/var/app/node_modules/forest-express-mongoose/node_modules/bluebird/js/main/util.js:24:31)
    at Promise._settlePromiseFromHandler (/var/app/node_modules/forest-express-mongoose/node_modules/bluebird/js/main/promise.js:454:31)
    at Promise._settlePromiseAt (/var/app/node_modules/forest-express-mongoose/node_modules/bluebird/js/main/promise.js:530:18)
    at Promise._settlePromises (/var/app/node_modules/forest-express-mongoose/node_modules/bluebird/js/main/promise.js:646:14)
    at Async._drainQueue (/var/app/node_modules/forest-express-mongoose/node_modules/bluebird/js/main/async.js:177:16)
    at Async._drainQueues (/var/app/node_modules/forest-express-mongoose/node_modules/bluebird/js/main/async.js:187:10)
    at Immediate.Async.drainQueues (/var/app/node_modules/forest-express-mongoose/node_modules/bluebird/js/main/async.js:15:14)
    at runCallback (timers.js:789:20)
    at tryOnImmediate (timers.js:751:5)
    at processImmediate [as _immediateCallback] (timers.js:722:5)

Context

The issue seems to come from the depth of my model

new Schema({
  // ...
  meta: {
    stats: {
      updatedAt: {type: Date, default: Date.now()},
      // ...
    }
  }
})

I could fix this by adding a condition if (!_.isNil(dest) && _.isPlainObject(field.type)) here https://github.com/ForestAdmin/forest-express/blob/8bd2bb1e91c29c7955dd82a951b868044519cab6/src/serializers/resource.js#L59. But it's a parent project, so I don't know the consequences this fix can have on forest-express-sequelize.

  • Package Version: 2.12.0
  • Express Version: 4.16.2
  • Mongoose Version: 5.2.4
  • MongoDB Version: 3.6.3

bybrunobarros avatar Aug 03 '18 11:08 bybrunobarros