-
Notifications
You must be signed in to change notification settings - Fork 120
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 new_version() actually creates a new version with a correct "modified" property value. #330
Conversation
correct "modified" property value.
Codecov Report
@@ Coverage Diff @@
## master #330 +/- ##
==========================================
- Coverage 98.17% 98.12% -0.06%
==========================================
Files 123 124 +1
Lines 14160 13873 -287
==========================================
- Hits 13902 13613 -289
- Misses 258 260 +2
Continue to review full report at Codecov.
|
stix2/utils.py
Outdated
new_modified = get_timestamp() | ||
# Ensure the new is newer than the old! | ||
if new_modified <= old_modified: | ||
new_modified = old_modified + dt.timedelta(microseconds=1000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to use microseconds=1000
instead of milliseconds=1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timedelta
doesn't have a milliseconds field, but I guess it does support it as a kwarg. I hadn't realized that.
One thing I did think of though, is that if new_modified
is later but less than a millisecond later, you may still wind up with a duplicate modified
field due to loss of precision when it is truncated to milliseconds. What is really needed is to ensure that new_modified
and old_modified
represent different milliseconds. This is guaranteed if they're >= 1 millisecond different, but not necessarily if they are < 1 millisecond different (but it's still possible). So it probably actually needs further modification.
when the current time is too close to the old "modified" time (but they are not equal).
I pushed an update to hopefully handle the case when the current timestamp is too close to the old |
@chisholm - |
As long as this library truncates to 3 decimal digits, we will need to ensure that timestamps are produced which will not accidentally become equal when extra precision is lost. We may need a separate issue to relax the millisecond precision requirement throughout the codebase. Part of that will probably be a revision to the design of the Edit: oops, I see you created issue #350 already! |
Superseded by #374. |
Fixes #329 .
Now, if the current timestamp is not later than the old modified property value, the new modified value is set to the old value plus one millisecond.