Return 400 for out-of-range _lastUpdated - #5819
Open
Rachit Shrivastava (v-rachitsh) wants to merge 4 commits into
Open
Rachit Shrivastava (v-rachitsh) wants to merge 4 commits into
Rachit Shrivastava (v-rachitsh) wants to merge 4 commits into
Conversation
Rachit Shrivastava (v-rachitsh)
requested a review
from a team
as a code owner
September 14, 2026 22:34
…personal/v-rachitsh/bug204940
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.
Description
Fixes IcM 848848621 (FHIR001 – HTTP Internal Error threshold reached).
GET /Patient?_lastUpdated=le9999-12-31T23:59:59.9999999returned a 500.LastUpdatedToResourceSurrogateIdRewriterconverts_lastUpdatedpredicatesinto
ResourceSurrogateIdpredicates. Because surrogate IDs only carrymillisecond resolution,
<= Tis rewritten as< trunc(T) + 1ms. For valuesin the last millisecond of
DateTime.MaxValue, that addition throwsArgumentOutOfRangeExceptionfromDateTime.AddTicks. Separately, because thesurrogate ID left-shifts ticks by 3 bits,
IdHelper.ToIdcan only representdatetimes up to ~year 3654 and throws via
EnsureArg.IsLtebeyond that.Neither exception is mapped in
OperationOutcomeExceptionFilterAttribute, soboth surfaced as 500s and counted against the FHIR001 internal-error monitor.
Changes
LastUpdatedToResourceSurrogateIdRewriternow validates the incoming valueagainst
MaxSupportedLastUpdatedand throwsBadRequestException(400)before the arithmetic can overflow. The bound reserves one millisecond of
headroom below
IdHelper.MaxDateTimeso the+1msrounding staysrepresentable.
LastUpdatedValueOutOfRangeresource string naming the max value.BadRequestExceptionwas chosen deliberately:InvalidSearchOperationExceptionmaps to 403, not 400.
Affected queries
All of these returned 500 and now return 400:
_lastUpdated=le9999-12-31T23:59:59.9999999(the ICM repro)_lastUpdated=le9999-12-31(date-only End expansion)_lastUpdated=9999-12-31(eq range upper bound)_lastUpdated=gt|ge|lt9999-12-31T23:59:59.9999999_lastUpdated=gt5000-01-01T00:00:00Z(surrogate-ID ceiling, ~year 3654)Cosmos DB is unaffected — it filters on
lastUpdateddirectly.Related issues
Addresses AB#204940.
Testing
Describe how this change was tested.
FHIR Team Checklist
Semver Change (docs)
Patch|Skip|Feature|Breaking (reason)