fix: use millisecond precision for dataEntry metadata ETag#24046
Open
stian-sandvold wants to merge 2 commits into
Open
fix: use millisecond precision for dataEntry metadata ETag#24046stian-sandvold wants to merge 2 commits into
stian-sandvold wants to merge 2 commits into
Conversation
… collisions The dataEntry/metadata ETag was hashed from a last-modified timestamp truncated to whole seconds (DateUtils.toLongDate). When a metadata change landed in the same wall-clock second as a previous fetch, the ETag was unchanged, so clients could be served a stale 304 Not Modified. This also intermittently broke CI: DataSetMetadataTest. dataSetMetadataEtagFunctionalityTest asserts the ETag changes after a dataset is created, which collided whenever the create happened in the same second as the prior read (~25-30% of master api-test runs). Switch to DateUtils.toLongDateWithMillis so the timestamp keeps millisecond precision. The MD5 hash length is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Update the expected hash in testGetEtag to match the millisecond-precision input, and add testGetEtagDistinguishesSubSecondChanges to lock in that two timestamps one millisecond apart now produce different ETags. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #24046 +/- ##
==========================================
Coverage 69.04% 69.04%
- Complexity 709 1437 +728
==========================================
Files 3684 3684
Lines 141646 141647 +1
Branches 16453 16453
==========================================
+ Hits 97797 97798 +1
Misses 36243 36243
Partials 7606 7606
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 2 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
enricocolasante
approved these changes
Jun 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What
The
GET /api/dataEntry/metadataETag is built from the latestlastUpdatedtimestamp across the relevant metadata types, hashed together with the user UID. That timestamp was formatted withDateUtils.toLongDate, which truncates to whole seconds. This bumps it toDateUtils.toLongDateWithMillisso sub-second changes are reflected in the ETag.Why
With second-level precision, two distinct metadata states that happen within the same wall-clock second produce the same ETag. Consequences:
304 Not Modifiedand miss the update until the next change.DataSetMetadataTest.dataSetMetadataEtagFunctionalityTestcreates a dataset and asserts the ETag changed (line 103). When the create lands in the same second as the preceding read, the ETags collide and the assertion fails. This has been intermittently failing theRun api testsjob on master (the same test/assertion across multiple unrelated commits, ~25-30% of runs).Millisecond precision makes same-instant collisions astronomically unlikely and fixes both issues. The MD5 hash length is unchanged, so the existing 34-character ETag assertions still hold.
Testing
mvn -pl dhis-web-api spotless:checkpasses.dataSetMetadataEtagFunctionalityTestcontinues to cover the behaviour.🤖 Generated with Claude Code