Repository navigation
Conversation
…ze#13027 & sequelize#12583) Adding JSON fields to rows regardless if requested or not breaks AbstractQuery::_groupJoinData() for example.
|
Cross linking issue that sent me on this debugging journey ForestAdmin/forest-express-sequelize#723 |
There was a problem hiding this comment.
Please update this pull request to match the template and / or match contributing guidelines.
There's not much info here and I'm not sure what the issue is.
|
@allawesome497 Thanks for the feedback. Updated the description. |
I'm still not sure what the issue is, can you give more info like:
|
|
I sincerely am not sure if this now all about satisfying bureaucracy :| However, here's a minimal example based on pseudo code: const attributes = {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
whatever: {
type: DataTypes.STRING,
allowNull: false
},
evilJSONField: {
type: DataTypes.JSON,
allowNull: false,
parse: true
}
};
sequelize.define('Demos', attributes, { timestamps: true });Query: await db.demo.sync({ alter: true });
await db.demo.truncate({ logging: console.log });
await db.demo.create({ whatever: 'foo', evilJSONField: JSON.stringify(['random', 'data']) });
const records = await db.demo.findAll({ attributes: ['id', 'whatever'], raw: true });
console.log(records);This would trigger following select query: And it will return: [ { id: 1, whatever: 'foo', evilJSONField: null } ]See that |
wbourne0
left a comment
There was a problem hiding this comment.
I edited your comment to use syntax highlighting. Thanks for adding code samples + the clarification.
Looks fine once linting is fixed. Can you also add a test for this to prevent regression?
| if (DataTypes.JSON.parse) { | ||
| return DataTypes.JSON.parse(modelField, this.sequelize.options, | ||
| row[modelField.fieldName]); | ||
| if(row[modelField.fieldName] !== undefined) { |
There was a problem hiding this comment.
oh also: it looks like this doesn't fix #13027.
for that you should probably do something like:
| if(row[modelField.fieldName] !== undefined) { | |
| if(typeof row[modelField.fieldName] === 'string') { |
My comment has not been addressed - will approve once that's fixed.
Adding JSON fields to rows regardless if requested or not breaks AbstractQuery::_groupJoinData() for example.
Fixes #13027 & #12583