You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var Sequelize = require('sequelize');
function JsonField(db, modelName, fieldName, options) {
var self = this;
options = options || {};
process.nextTick(function() {
function stringifyField(instance) {
if (typeof instance.dataValues[fieldName] !== 'string' && instance.dataValues[fieldName]) {
instance.setDataValue(fieldName, JSON.stringify(instance.getDataValue(fieldName)));
return self;
} else if (instance.dataValues[fieldName] === 'null' || !instance.dataValues[fieldName]) {
instance.setDataValue(fieldName, undefined);
}
}
if (typeof db.models === 'object' && db.models.hasOwnProperty(modelName) && typeof db.models[modelName].hook === 'function') {
db.models[modelName].hook('beforeUpdate', stringifyField);
db.models[modelName].hook('beforeCreate', stringifyField);
}
});
var model = {
type: options.type || Sequelize.TEXT,
get: function() {
var currentValue = this.getDataValue(fieldName);
if (typeof currentValue == 'string') {
try {
this.dataValues[fieldName] = JSON.parse(currentValue);
Getting this error for emptystring '' values in MySQL JSON columns
err_stack:
SyntaxError: Unexpected end of JSON input\n
at JSON.parse (<anonymous>)\n
at model.get (.../node_modules/sequelize-json/index.js:28:43)\n
at model.get (.../node_modules/sequelize/lib/model.js:3244:41)\n
at model.get (.../node_modules/sequelize/lib/model.js:3265:33)\n
Right here, currentValue is empty string (typeof string, and '').
This was working, and this morning I started upgrading from Sequelize 3.30 to 4.38 and found this.
Is it something that needs a check for empty string?
The text was updated successfully, but these errors were encountered:
definitely an error on our side (we should remove this invalid json from our DB),
but thought it was strange that it started happening (and used to work before this morning).
perhaps sequelize used to check for emptystring, safety-checking before calling the sequelize-json getter, and now no longer does...
.../node_modules/sequelize-json/index.js:28
Getting this error for emptystring
''
values in MySQL JSON columnsRight here,
currentValue
is empty string (typeof string
, and''
).This was working, and this morning I started upgrading from Sequelize 3.30 to 4.38 and found this.
Is it something that needs a check for empty string?
The text was updated successfully, but these errors were encountered: