Skip to content

fix(paranoid): use Utils.now to query for paranoid records - #8485

Merged
sushantdhiman merged 4 commits into
masterfrom
fix-8006
Oct 15, 2017
Merged

sushantdhiman merged 4 commits into
masterfrom
fix-8006

Conversation

@sushantdhiman

@sushantdhiman sushantdhiman commented Oct 14, 2017 •

Copy link
Copy Markdown
Contributor

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

Fixes #8202
Fixes #8006
Closes #8204
Closes #7787

@sushantdhiman
sushantdhiman requested review from a team and janmeier October 14, 2017 11:01
@sushantdhiman

Copy link
Copy Markdown
Contributor Author

Will also close #7787 but we dont have proper way to test that db / app server timezone difference.

If we distill what all those threads are saying, we can conclude

  1. destroy use Utils.now to set deletedAt
  2. _paranoidClause use CURRENT_TIMESTAMP to query for those records

If db and app server use different timezone, this will surely get incorrect records.

I think we should use application server time, hence changing _paranoidClause to use Utils.now (Although a few of these threads suggest otherwise, i.e. use database server time in destroy)

@eseliger

Copy link
Copy Markdown
Member

@sushantdhiman This sounds good! I'm down to using application server time for the clause.
One reason:
If other logic might create dates in the application as well, those should match dates in the database.

@codecov

codecov Bot commented Oct 14, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #8485 into master will increase coverage by <.01%.
The diff coverage is 100%.

@sushantdhiman
sushantdhiman merged commit 9558242 into master Oct 15, 2017
@sushantdhiman
sushantdhiman deleted the fix-8006 branch October 15, 2017 10:58
@gabegorelick

Copy link
Copy Markdown
Contributor

Correct me if I'm wrong, but I don't think this fundamentally fixes a lot of the linked issues because Date in JS is not a monotonic time source. In other words, it can move backwards (NTP, leap seconds etc) which would mess queries up.

Happy to file an issue if you want to move discussion elsewhere.

@sushantdhiman

Copy link
Copy Markdown
Contributor Author

@gabegorelick Most of linked issue are appearing because querying and setting of deletedAt are using entirely different construct (new Date vs CURRENT_TIMESTAMP), which would always fail for cross timezone interactions.

With this PR both construct aligns to use singular source i.e. new Date. This will ensure paranoid records aren't returned even if clocks aren't synced, because now we are using only app server clock for all cases.

Leap seconds like issues are a bit hard to test and honestly I don't worry about them in current context which is failing paranoid for every cross timezone case.

But you are free to discuss this among other contributors by opening an issue if you like to

@gabegorelick

Copy link
Copy Markdown
Contributor

Thanks @sushantdhiman. We can continue discussion in #8496.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Same second query for paranoid tables returning soft deleted records Soft deleted rows are being returned in findAll using paranoid mode

4 participants