Repository navigation
Closed
Labels
status: wipFor issues and PRs. Applied when the PR is not ready yet / when work to close the issue has started.type: otherDEPRECATED: replace with the "meta" issue type
Description
What are you doing?
Here is a repo reproducing the issue.
In Sequelize 5.0.0-beta.13:
const connection = new Sequelize(database, username, password, {
dialect,
host,
define: {
freezeTableName: true,
underscored: false,
createdAt: 'createdAt',
updatedAt: 'updatedAt'
},
logging: message => {
console.log(message);
}
});
const Task = connection.define('task', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
createdAt: {
field: 'created_at',
type: Sequelize.DATE,
allowNull: false
},
updatedAt: {
field: 'updated_at',
type: Sequelize.DATE,
allowNull: false
},
name: {
type: Sequelize.TEXT,
allowNull: false
},
status: {
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 0
}
});
(async() => {
...
await Task.create({ name: 'First task', status: 1 }, { transaction });
await Task.update({ status: 2 }, { where: { status: 1 }, transaction });
})();What do you expect to happen?
Output valid SQL queries with inserted binded parameters' values in console:
INSERT INTO "task" ("id","created_at","updated_at","name","status") VALUES (DEFAULT,'2018-10-23 13:58:05.380 +00:00','2018-10-23 13:58:05.380 +00:00','First task',1) RETURNING *
UPDATE "task" SET "status"=2,"updated_at"='2018-10-23 13:58:05.398 +00:00' WHERE "status" = 1What is actually happening?
I get SQL queries with tokens starting with $ instead of parameters' values:
INSERT INTO "task" ("id","created_at","updated_at","name","status") VALUES (DEFAULT,$1,$2,$3,$4) RETURNING *;
UPDATE "task" SET "status"=$1,"updated_at"=$2 WHERE "status" = $3Note that bulkCreate method works fine.
Dialect: postgres
Dialect version: 7.5.0
Database version: 9.5.14
Sequelize version: 5.0.0-beta.13
Tested with latest release: Yes (latest beta version 5.0.0-beta.13)
Reacted by lerit and Vahid Alimohamadi
Metadata
Metadata
Assignees
Labels
status: wipFor issues and PRs. Applied when the PR is not ready yet / when work to close the issue has started.type: otherDEPRECATED: replace with the "meta" issue type
Activity
[-]Invalid logging of single `INSERT` and `UPDATE` SQL queries[/-][+]Invalid logging of single INSERT and UPDATE SQL queries[/+]sushantdhiman commentedon Oct 27, 2018
Sequelize v5 is using bound parameters for INSERT and UPDATE statements. I guess we can append data in query logs
spearmootz commentedon Nov 27, 2018
this is still happening in beta.14
lerit commentedon Jan 7, 2019
same question here
sheldhur commentedon Mar 23, 2019
As a temporary solution, you can get bindings from the logger args.
PS. @sushantdhiman It would be nice to pass a logger args as one object
{sql, benchmark, bind, instance}eggerand13 commentedon Jun 25, 2019
Is there already some kind of solution for this?
Today we were forced to update to v5 due to the critical SQL injection vulnerability in Sequelize (https://snyk.io/vuln/SNYK-JS-SEQUELIZE-450221) but now we are lacking the ability to see the insert logs.
superlbr commentedon Jul 20, 2019
it's better to have a timetable for closing issues, not just let it hang, let pr hang
papb commentedon Jul 20, 2019
Hello @superlbr, I understand that you are anxious for fixes, we all are! Unfortunately, open source development has this kind of problems...
If you really need the fix from that PR the way it currently is, read this comment I wrote on another issue and do something similar.
superlbr commentedon Jul 23, 2019
@papb for me, just modify code in node_modules, 1 min. What I suggest is merge pr first and implement later or by someone else.
terrynguyen255 commentedon Aug 20, 2019
Sorry, any updates?
sushantdhiman commentedon Sep 19, 2019
Fixed by #11267
hiteshgarg14 commentedon Feb 6, 2020
Set
logQueryParameters: truewhile creating a new Sequelize class instance.For eg,
ezze commentedon Feb 26, 2020
@sushantdhiman @papb I believe that it should be reopened. Still the issue in 5.21.5.
I updated the repo to reproduce.
ezze commentedon Feb 26, 2020
Ok, setting
logQueryParameterstotruedoesn't work for me. Result is the same.Anyway, if it would worked, there are still questions for me.
Why do we need
logQueryParametersat all and why do we need to log placeholders by default? v4 was working without it.Current default behavior is useless. Even if we consider that logging placeholders is what we need it doesn't work as expected. Placeholders are logged for single inserts and updates while values are logged for bulk inserts and selects.
terrynguyen255 commentedon Feb 27, 2020
Works with
"sequelize": "^5.21.2"@ezzeHowever, I agree with you, for debugging, I have to copy params into placeholders before I can execute them at DB.
ezze commentedon Feb 27, 2020
@Nogias9x, does it depend on dialect? I use
postgresandlogQueryParametersdoesn' work for me with the repo I mentioned above.terrynguyen255 commentedon Feb 28, 2020
Sorry, I'm not sure @ezze
phoenixweiss commentedon May 7, 2021
logQueryParameters: truestill not working for a singleupdateorinsertin"sequelize": "^6.6.2".YavorK commentedon Jun 10, 2021
I refined the function a bit because it was outputting too much info sometimes so here it is only for query + params