Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that latest() is idempotent. #862

Merged
merged 2 commits into from
Sep 1, 2021
Merged

Conversation

jeking3
Copy link
Contributor

@jeking3 jeking3 commented Aug 11, 2021

Description

Two records with the same history_date cannot be retrieved idempotently with latest(). The get_latest_by meta property uses history_date which means if multiple records have the same timestamp, the resulting record returned by the database is not predictable (it would depend on the behavior of the database). If history_date is not indexed the result may be different than if it is indexed, for example (this was observed in #729). The meta property should include sorting by history_id.

Related Issue

This closes #861

Motivation and Context

When latest() is not idempotent, the behavior can change over time (for example adding an index).

How Has This Been Tested?

The unit tests exercise this behavior.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have run the make format command to format my code
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have added my name and/or github handle to AUTHORS.rst
  • I have added my change to CHANGES.rst
  • All new and existing tests passed.

@codecov
Copy link

codecov bot commented Aug 11, 2021

Codecov Report

Merging #862 (183716b) into master (be7b8b6) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #862   +/-   ##
=======================================
  Coverage   97.67%   97.68%           
=======================================
  Files          18       19    +1     
  Lines         990      994    +4     
  Branches      151      151           
=======================================
+ Hits          967      971    +4     
  Misses         10       10           
  Partials       13       13           
Impacted Files Coverage Δ
simple_history/models.py 97.86% <ø> (ø)
simple_history/registry_tests/tests.py 95.87% <ø> (ø)
...lmodelwithcustomattrforeignkey_options_and_more.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update be7b8b6...183716b. Read the comment docs.

@jeking3
Copy link
Contributor Author

jeking3 commented Aug 11, 2021

One job in PR #863 just failed because of this issue. This code is not in that PR.

Copy link
Contributor

@sarathak sarathak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code look good.

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.

test_sameinstant is not idempotent
2 participants