Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected error: attribute.split is not a function #500

Open
whollacsek opened this issue Sep 2, 2020 · 2 comments
Open

Unexpected error: attribute.split is not a function #500

whollacsek opened this issue Sep 2, 2020 · 2 comments

Comments

@whollacsek
Copy link

Expected behavior

Should not throw error while creating a new row from the Forest UI.

Actual behavior

Can not create new row in table because of TypeError: attribute.split is not a function in https://github.com/SeyZ/jsonapi-serializer/blob/b0315e95e6156395590094c3c48fce6e3c75bf95/lib/serializer-utils.js#L293, see stack trace below.

If I add a console.log(attribute) to see what's being passed I get:

id
[ 'id',
  'createdAt',
  'name',
  'type',
  'account',
  'attributReportAttributes' ]
<STACK TRACE>

Somehow an array was passed over instead of the content (?) of the array.

This is a brand new project I just generated using the Docker image, no further modifications were applied.

Failure Logs

[forest] 🌳🌳🌳  Unexpected error: attribute.split is not a function
TypeError: attribute.split is not a function
    at /usr/src/app/node_modules/jsonapi-serializer/lib/serializer-utils.js:294:42
    at /usr/src/app/node_modules/lodash/_createBaseFor.js:17:11
    at baseForOwn (/usr/src/app/node_modules/lodash/_baseForOwn.js:13:20)
    at /usr/src/app/node_modules/lodash/_createBaseEach.js:17:14
    at forEach (/usr/src/app/node_modules/lodash/forEach.js:38:10)
    at module.exports.perform (/usr/src/app/node_modules/jsonapi-serializer/lib/serializer-utils.js:292:5)
    at /usr/src/app/node_modules/jsonapi-serializer/lib/serializer.js:27:43
    at Array.forEach (<anonymous>)
    at collection (/usr/src/app/node_modules/jsonapi-serializer/lib/serializer.js:24:15)
    at module.exports.serialize (/usr/src/app/node_modules/jsonapi-serializer/lib/serializer.js:55:14)
    at new module.exports (/usr/src/app/node_modules/jsonapi-serializer/lib/serializer.js:65:17)
    at /usr/src/app/node_modules/forest-express-sequelize/node_modules/forest-express/dist/serializers/resource.js:201:14
    at tryCatcher (/usr/src/app/node_modules/forest-express-sequelize/node_modules/forest-express/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/usr/src/app/node_modules/forest-express-sequelize/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/usr/src/app/node_modules/forest-express-sequelize/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/usr/src/app/node_modules/forest-express-sequelize/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/usr/src/app/node_modules/forest-express-sequelize/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:729:18)
    at Promise._fulfill (/usr/src/app/node_modules/forest-express-sequelize/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:673:18)
    at Promise._resolveCallback (/usr/src/app/node_modules/forest-express-sequelize/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:466:57)
    at Promise._settlePromiseFromHandler (/usr/src/app/node_modules/forest-express-sequelize/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:559:17)
    at Promise._settlePromise (/usr/src/app/node_modules/forest-express-sequelize/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/usr/src/app/node_modules/forest-express-sequelize/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/usr/src/app/node_modules/forest-express-sequelize/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:729:18)
    at Promise._fulfill (/usr/src/app/node_modules/forest-express-sequelize/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:673:18)
    at Promise._resolveCallback (/usr/src/app/node_modules/forest-express-sequelize/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:466:57)
    at Promise._settlePromiseFromHandler (/usr/src/app/node_modules/forest-express-sequelize/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:559:17)
    at Promise._settlePromise (/usr/src/app/node_modules/forest-express-sequelize/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/usr/src/app/node_modules/forest-express-sequelize/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/usr/src/app/node_modules/forest-express-sequelize/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:729:18)
    at Promise._fulfill (/usr/src/app/node_modules/forest-express-sequelize/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:673:18)
    at MappingPromiseArray.PromiseArray._resolve (/usr/src/app/node_modules/forest-express-sequelize/node_modules/forest-express/node_modules/bluebird/js/release/promise_array.js:127:19)
    at MappingPromiseArray._promiseFulfilled (/usr/src/app/node_modules/forest-express-sequelize/node_modules/forest-express/node_modules/bluebird/js/release/map.js:108:18)
    at Promise._settlePromise (/usr/src/app/node_modules/forest-express-sequelize/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:609:26)
    at Promise._settlePromise0 (/usr/src/app/node_modules/forest-express-sequelize/node_modules/forest-express/node_modules/bluebird/js/release/promise.js:649:10)

Context

Project was created using the Docker method.

  • Package Version: "^6.0.0",
  • Express Version: "~4.16.3",
  • Sequelize Version: "~5.15.1",
  • Database Dialect: Postgres
  • Database Version: 12
@whollacsek
Copy link
Author

I think I have an idea why this is happening...

Problem

If my understanding is correct there is a fatal flaw in the logic of the serializer: https://github.com/ForestAdmin/forest-express/blob/2784cf8a1aa2fe4bdc13ccbe324a9e1b5d3563be/src/serializers/resource.js#L152

The serializationOptions object contains an attributes key that should hold an array. However when getAttributesFor(serializationOptions, schema.fields) is called, if the database schema has a table called attribute it'll be serialized into attributes thus overriding the initial attributes field in the serializationOptions object.

Solution

It would be the best to group all database schema related attributes into a separate field in serializationOptions instead of injecting them right at the root.

@chihabeeddine
Copy link

I had the same probleme, I hade to change the table name to make it work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants