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
{{ message }}
Repository navigation
Same second query for paranoid tables returning soft deleted records #8202
sequelize.define('user',{//...column definitions},{paranoid: true});User.find({where: {id: req.params.id}}).then((user)=>{console.log(user);user.destroy().then(()=>{User.find({where: {id: req.params.id}}).then((deletedUser)=>{console.log(deletedUser);console.log(newDate(newDate().toUTCString()).toISOString());});});});//run a second laterUser.find({where: {id: req.params.id}}).then((user)=>{console.log(user);});
What do you expect to happen?
Second console.log should return null.
What is actually happening?
Second console.log is returning the object again with a deletedAt field entered that matches the third console.log's output. Remote MySQL server runs in UTC time. Occurs on local development stations in EST as well as servers running in UTC time. Similar to #7204.
Running another query a second later will return null.
Dialect: mysql Database version: 5.7.11 Sequelize version: 4.7.5
I'm seeing the same thing using sqlite, though #7290 mentions moving from $gte to $gt was meant to be a fix for it.
The find* queries use table.deleted_at > CURRENT_TIMESTAMP in the where clause.
SELECT `id`, `group`, `created_at`, `updated_at`, `deleted_at`
FROM `groups` AS `group`
WHERE (`group`.`deleted_at` > CURRENT_TIMESTAMP OR `group`.`deleted_at` IS NULL);`
It might be related to CURRENT_TIMESTAMP only being second resolution, but datetime is millisecond
Running manual queries with constructed dates including milliseconds works as expected:
sqlite> update groups set deleted_at = strftime('%Y-%m-%d %H:%M:%f', 'now'); select * from groups where deleted_at > strftime('%Y-%m-%d %H:%M:%f', 'now');
sqlite>
Whereas using CURRENT_TIMESTAMP returns the "deleted" record like sequelize:
sqlite> update groups set deleted_at = strftime('%Y-%m-%d %H:%M:%f', 'now'); select * from groups where deleted_at > CURRENT_TIMESTAMP;
9e7453ca-4424-44f4-98fc-8f71e073c55a|test|2017-09-12 08:23:21.707 +00:00|2017-09-12 08:23:21.707 +00:00|2017-09-12 09:12:59.802
Activity
deployable commentedon Sep 12, 2017
I'm seeing the same thing using sqlite, though #7290 mentions moving from
$gteto$gtwas meant to be a fix for it.The
find*queries usetable.deleted_at > CURRENT_TIMESTAMPin the where clause.It might be related to
CURRENT_TIMESTAMPonly being second resolution, but datetime is millisecondRunning manual queries with constructed dates including milliseconds works as expected:
Whereas using
CURRENT_TIMESTAMPreturns the "deleted" record like sequelize:deployable commentedon Sep 12, 2017
The same test suite I found the problem with on sqlite works as expected in mysql/maria/postgres.
apricote commentedon Sep 30, 2017
A fix that is working for me is contained in PR #8204
There is a test case missing though, so it can not be merged yet.