fix: reject invalid/negative lastUpdatedDuration on dataValueSets export instead of silently ignoring it#24470
Open
jason-p-pickering wants to merge 4 commits into
Conversation
…ort instead of silently ignoring it
DateUtils.getDuration() returns null on any parse failure (its regex requires
unsigned digits, so negative durations like "-5d" never match), and
DefaultDataExportService.decodeParams() called it unchecked, so a malformed or
negative lastUpdatedDuration was silently discarded - indistinguishable from
"not provided". If it was the client's only time filter, this surfaced as the
unrelated E2002 error instead of pointing at the actual problem; otherwise it
was dropped with no error at all.
ErrorCode.E2005 ("Duration is not valid: `{0}`") already exists for exactly
this and is used by the sibling DefaultCompleteDataSetRegistrationExchangeService
for its createdDuration parameter, but was never wired up here.
decodeParams() now throws ConflictException(E2005, rawValue) when
lastUpdatedDuration is non-blank but fails to parse. lastUpdatedDuration=0d
is deliberately left valid - it parses successfully (Duration.ZERO) and is a
well-defined (if narrow) "as of right now" filter, analogous to
startDate == endDate being a valid zero-width date range.
Verified via mutation testing: temporarily disabled the new guard, confirmed
only the two negative-case tests failed (the 0d-is-valid test stayed green),
then restored. No regressions in DataExportServiceExportTest,
DataValueServiceTest, or DataValueSetControllerTest.
Related to DHIS2-21821.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #24470 +/- ##
=============================================
+ Coverage 30.40% 57.11% +26.70%
+ Complexity 1196 608 -588
=============================================
Files 3679 3711 +32
Lines 142430 143849 +1419
Branches 16619 16765 +146
=============================================
+ Hits 43308 82160 +38852
+ Misses 94894 54149 -40745
- Partials 4228 7540 +3312
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1765 files with indirect coverage changes Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
…n-silently-ignored
david-mackessy
approved these changes
Jul 17, 2026
…n-silently-ignored
…n-silently-ignored
|
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.


Summary
Found while reviewing edge cases during DHIS2-21821 (#24465).
GET /api/dataValueSetsaccepts alastUpdatedDurationparameter, but a malformed or negative value (e.g.-5d,abc,5x) is silently discarded with no error — the request proceeds as if it was never supplied.DateUtils.getDuration(String)returnsnullon any parse failure (its regex^(\d+)(d|h|m|s)$requires unsigned digits, so-5dnever matches).DefaultDataExportService.decodeParams()called it unchecked, so an invalid string is indistinguishable from "not provided."lastUpdatedDurationwas the client's only time filter, this surfaces as the unrelatedE2002("must specify a filter") error even though the client did specify one. Otherwise it's dropped with zero indication to the caller.ErrorCode.E2005("Duration is not valid:{0}") already exists and is used for exactly this by the siblingDefaultCompleteDataSetRegistrationExchangeService(itscreatedDurationparam), but was never wired up forDataExportParams.Not in scope:
lastUpdatedDuration=0dis deliberately left valid — it parses successfully (Duration.ZERO) and is a well-defined, if narrow, "as of right now" filter, the same reasoning asstartDate == endDatebeing a valid zero-width date range (already covered byDataExportParamsTest).Fix
DefaultDataExportService.decodeParams()now throwsConflictException(ErrorCode.E2005, rawValue)whenlastUpdatedDurationis non-blank but fails to parse, mirroring the existingcreatedDurationvalidation pattern in the sibling service.Test plan
DefaultDataExportServiceTest(Mockito-based unit test): negative duration → E2005, malformed duration → E2005,0d→ no exception0dtest stayed green), then restored (git diffon the production logic nets to the same guard, cleanly re-added)DataExportServiceExportTest,DataValueServiceTest(integration, TestContainers),DataValueSetControllerTest(web-api integration) all passmvn spotless:checkclean🤖 Generated with Claude Code