Skip to content

fix(api): use timestamptz cast in GetInstanceStatsByTimestamp - #1592

Open
damnnmanyaa wants to merge 1 commit into
flatcar:mainfrom
damnnmanyaa:fix/instance-stats-timezone
Open

fix(api): use timestamptz cast in GetInstanceStatsByTimestamp#1592
damnnmanyaa wants to merge 1 commit into
flatcar:mainfrom
damnnmanyaa:fix/instance-stats-timezone

Conversation

@damnnmanyaa

@damnnmanyaa damnnmanyaa commented Aug 15, 2026

Copy link
Copy Markdown

Fixes flatcar/Flatcar#2324

Bug

GetInstanceStatsByTimestamp casts its comparison literal to Postgres's timestamp type (no timezone) instead of timestamptz. 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 timestamptz instead, 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.

  • Confirmed the test fails against the old timestamp cast (0 rows returned instead of 1)
  • Confirmed it passes against the fix
  • Ran the full backend suite (go test -p 1 ./pkg/... -count=1) all packages pass

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>
Copilot AI lite review requested due to automatic review settings August 15, 2026 21:03
@damnnmanyaa
damnnmanyaa requested a review from a team as a code owner August 15, 2026 21:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nebraska: instance_stats query returns zero rows when DB session timezone isn't UTC

2 participants