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

Loader does not take any actions within Model.set into account #57

Closed
nedrocks opened this issue Jun 21, 2016 · 0 comments · Fixed by #58
Closed

Loader does not take any actions within Model.set into account #57

nedrocks opened this issue Jun 21, 2016 · 0 comments · Fixed by #58

Comments

@nedrocks
Copy link
Contributor

nedrocks commented Jun 21, 2016

Currently I am trying to load a model which has a Sequelize.TEXT field that stores a serialized JSON blob. Doing this outside of Postgres, I need to do the serialization / parsing within the model set and get commands. Currently sequelize-fixtures loader doesn't account for these set methods which forces the system to try and sanitize an object as though it were a string, giving me this error:

Unhandled rejection TypeError: val.replace is not a function
    at Object.SqlString.escape (/Volumes/pocketship/pocketship/node_modules/sequelize/lib/sql-string.js:63:15)
    at Object.QueryGenerator.escape (/Volumes/pocketship/pocketship/node_modules/sequelize/lib/dialects/abstract/query-generator.js:977:22)
    at Object.QueryGenerator.whereItemQuery (/Volumes/pocketship/pocketship/node_modules/sequelize/lib/dialects/abstract/query-generator.js:2260:22)
    at /Volumes/pocketship/pocketship/node_modules/sequelize/lib/dialects/abstract/query-generator.js:1891:25
    at /Volumes/pocketship/pocketship/node_modules/sequelize/node_modules/lodash/lodash.js:4389:15
    at baseForOwn (/Volumes/pocketship/pocketship/node_modules/sequelize/node_modules/lodash/lodash.js:2652:24)
    at Function.forOwn (/Volumes/pocketship/pocketship/node_modules/sequelize/node_modules/lodash/lodash.js:12254:24)
    at Object.QueryGenerator.whereItemsQuery (/Volumes/pocketship/pocketship/node_modules/sequelize/lib/dialects/abstract/query-generator.js:1890:9)
    at Object.QueryGenerator.getWhereConditions (/Volumes/pocketship/pocketship/node_modules/sequelize/lib/dialects/abstract/query-generator.js:2325:19)
    at Object.QueryGenerator.selectQuery (/Volumes/pocketship/pocketship/node_modules/sequelize/lib/dialects/abstract/query-generator.js:1451:28)
    at [object Object].QueryInterface.select (/Volumes/pocketship/pocketship/node_modules/sequelize/lib/query-interface.js:669:25)
    at [object Object].<anonymous> (/Volumes/pocketship/pocketship/node_modules/sequelize/lib/model.js:1390:32)
    at [object Object].tryCatcher (/Volumes/pocketship/pocketship/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Volumes/pocketship/pocketship/node_modules/bluebird/js/release/promise.js:504:31)
    at Promise._settlePromise (/Volumes/pocketship/pocketship/node_modules/bluebird/js/release/promise.js:561:18)
    at Promise._settlePromise0 (/Volumes/pocketship/pocketship/node_modules/bluebird/js/release/promise.js:606:10)
    at Promise._settlePromises (/Volumes/pocketship/pocketship/node_modules/bluebird/js/release/promise.js:685:18)
    at Async._drainQueue (/Volumes/pocketship/pocketship/node_modules/bluebird/js/release/async.js:138:16)
    at Async._drainQueues (/Volumes/pocketship/pocketship/node_modules/bluebird/js/release/async.js:148:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/Volumes/pocketship/pocketship/node_modules/bluebird/js/release/async.js:17:14)
    at processImmediate [as _immediateCallback] (timers.js:383:17)

My model definition has been simplified to build a reproducible case:

const Role = database.define('Role', {
  permissions: {
    type: Sequelize.TEXT,
    allowNull: false,
    get(): Object {
      return JSON.parse(this.getDataValue('permissions'));
    },
    set(val: Object): void {
      this.setDataValue('permissions', JSON.stringify(val))
    },
  }
}, {
  tableName: 'roles',
  underscored: true
});

And the loaded fixture is the following:

[
  {
    "model": "Role",
    "data": {
      "permissions": {
        "*": "*"
      }
    }
  }
]
nedrocks added a commit to nedrocks/sequelize-fixtures that referenced this issue Jun 21, 2016
…DB, thus run the set operation on loading a fixture. This fixes domasx2#57
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

Successfully merging a pull request may close this issue.

1 participant