fix(api): use timestamptz cast in GetInstanceStatsByTimestamp - #1592
Open
damnnmanyaa wants to merge 1 commit into
Open
fix(api): use timestamptz cast in GetInstanceStatsByTimestamp#1592damnnmanyaa wants to merge 1 commit into
damnnmanyaa wants to merge 1 commit into
Conversation
Fixes flatcar/Flatcar#2324. The query previously cast its timestamp literal to Postgres's timestamp type (no timezone), causing Postgres to reinterpret it using the session's local timezone and silently return zero rows whenever that session wasn't UTC. Signed-off-by: Manya <174072426+damnnmanyaa@users.noreply.github.com>
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.
Fixes flatcar/Flatcar#2324
Bug
GetInstanceStatsByTimestamp casts its comparison literal to Postgres's
timestamptype (no timezone) instead oftimestamptz. Postgres reinterprets the resulting bare clock value using the database session's timezone, so the comparison silently returns zero rows whenever the session isn't UTC , no error, just an empty result set.Fix
Cast to
timestamptzinstead, so the comparison stays timezone-aware regardless of session timezone. One-line change, no behavior change for UTC sessions.Verification
Added a regression test that sets the session timezone to a non-UTC zone (America/New_York), seeds a row, and confirms the query still finds it.
timestampcast (0 rows returned instead of 1)go test -p 1 ./pkg/... -count=1) all packages pass