Repository navigation
Conversation
If dialect is MSSQL, use SYSDATETIMEOFFSET() instead of CURRENT_TIMESTAMP as the deletedAtDefaultValue
There was a problem hiding this comment.
@getglad Thank you for the PR. Could you add a test which was failing earlier with paranoid mode?
… where clause - unclear what the issue is
|
@harshithkashyap I have submitted a test, but the In my application code I can have something like: And my Am I missing something in the test setup? |
|
@harshithkashyap just thought I'd bump you - see if you had any input |
|
|
Will review once build is green. |
| let deletedAtDefaultValue = deletedAtAttribute.hasOwnProperty('defaultValue') ? deletedAtAttribute.defaultValue : null; | ||
|
|
||
| deletedAtDefaultValue = deletedAtDefaultValue || { $or: { $gt: model.sequelize.literal('CURRENT_TIMESTAMP'), $eq: null } }; | ||
| deletedAtDefaultValue = deletedAtDefaultValue || { $or: { $gt: this.sequelize.options.dialect === 'mssql' ? model.sequelize.literal('SYSDATETIMEOFFSET()') : model.sequelize.literal('CURRENT_TIMESTAMP'), $eq: null } }; |
There was a problem hiding this comment.
I would wrap this line
There was a problem hiding this comment.
# Conflicts: # test/integration/model/find.test.js
| expect(users.length).to.be.eql(1); | ||
| }); | ||
|
|
||
| if (dialect === 'sqlite') |
There was a problem hiding this comment.
please put braces for multiline statements.
Why is there different behaviour for SQLite?
There was a problem hiding this comment.
Will do on braces.
On SQLite:
The only difference is a .delay() after deleting a record. There appears to be some sort of race condition when deleting the record (https://travis-ci.org/sequelize/sequelize/builds/245954861) and immediately querying it back, which is what I was doing in my test. Only saw it on SQLite, but if I created 2 records, soft delete 1, and then findAll, I would get both records back. A brief delay seems to fix on SQLite, but sometimes caused an Error: Expected 0 running queries. 1 queries still running in [POSTGRES] Model constructor should allow the user to specify indexes in options, especially on Postgres test - thus only tested it on SQLite. It may be worth extending the delay some to get a more reliable result, but 500 seemed okay for my test.
There was a problem hiding this comment.
There was a problem hiding this comment.
A timeout sounds very brittle, especially if you don't know why it appears and why it only appears only for SQLite. We have some flakiness in tests in general which are solved when restarting jobs, but if it happens consistently, it indicates some bug in the code...
There was a problem hiding this comment.
I'm pretty sure it is just that the write (destory but with paranoid mode on) doesn't complete before the read (findAll) on SQLite. It isn't a timeout issue, just an opportunity for SQLite to fully register the change. All I meant to say was that lengthening the wait time reduces the brittleness, which I have done, so it should be strong from here on out. It may represent a problem with the SQLite syntax (honestly, I think it's just a virtue of SQLite itself), but this PR is to fix the syntax for MSSQL on reading over paranoid deleted rows. The SQLite fix in my test reliably resolves the issue for me over several tests.
The failure in the last travis ci build seems to be related to this test -
- far as I can tell unrelated to my PR.Other failures that have popped up inconsistently, but I don't believe are related to this PR:
sequelize/test/integration/model.test.js
Line 362 in 99d87df
- "no such file or directory, rename 'coverage/lcov.info' -> 'coverage/integration.info'"
Thoughts?
There was a problem hiding this comment.
All I'm saying is there is probably a better way to fix this than a timeout, a real application wouldn't do a timeout either. The fulfilled promise of the destroy query should mean that the query finished.
@sushantdhiman @janmeier
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂 |
If dialect is MSSQL, use SYSDATETIMEOFFSET() instead of CURRENT_TIMESTAMP as the deletedAtDefaultValue
Pull Request check-list
Please make sure to review and check all of these items:
npm run testornpm run test-DIALECTpass with this change (including linting)?Note: rpm run test-mssql reports 751 passing on the first step. There is a second step that wants to use the connection variables, but I am using the
msnodesqlv8+ a connection string, and I'm not sure how to pass that into the tests.Futurein the changelog?NOTE: these things are not required to open a PR and can be done afterwards / while the PR is open.
Description of change
When
sequelizesets thedeletedAttime stamp in paranoid mode, it submits a time stamp in the below format:... SET [deletedAt]=N'2017-06-13 11:35:41.000 +00:00'When
sequelizethen runsfindAllagainst the records, it submits... WHERE ([table].[deletedAt] > CURRENT_TIMESTAMP OR [table].[deletedAt] IS NULL);On MS SQL,
CURRENT_TIMESTAMPreturns:2017-06-13 11:35:41.000This results in returning all records.
While
SYSDATETIMEOFFSET()returns:2017-06-13 11:40:11.8163142 -00:00This results in returning all the undeleted records.
It's a minor change, but the only use of
CURRENT_TIMESTAMPI can find in the project.Closes #7419