Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set entity columns to be 'timestamp with time zone' to avoid TZ-related test failures #4720

Merged
merged 1 commit into from
Oct 10, 2024

Conversation

evankanderson
Copy link
Member

Summary

The Postgres TIMESTAMP type records a date and time irrespective of (ignoring) timezone. This aligns with the SQL standard, but they also have a TIMESTAMP WITH TIME ZONE (aka TIMESTAMPTZ) which is timezone aware. It turns out that lib/pq (at least) stores time.Time values into the database using local time for TIMESTAMP columns, but reads back the columns in the zero-timezone. In PDT (UTC+7), this results in reading back times which are 7 hours later than when they were stored. This mostly doesn't bother our code and tests at the moment, but it does break tests in internal/entities/properties/service, which use updated_at as a cache validation mechanism.

This PR migrates the TIMESTAMP fields added in 000090 to TIMESTAMPTZ in a way which should avoid table locks, and which causes the above tests to pass on my machine where they failed otherwise. Note that the tests would only fail for people in timezones west of GMT, so this probably wouldn't affect affect folks in CET or easterly.

Change Type

Mark the type of change your PR introduces:

  • Bug fix (resolves an issue without affecting existing features)
  • Feature (adds new functionality without breaking changes)
  • Breaking change (may impact existing functionalities or require documentation updates)
  • Documentation (updates or additions to documentation)
  • Refactoring or test improvements (no bug fixes or new functionality)

Testing

Unit tests pass for my on my local machine, where they failed before.

Review Checklist:

  • Reviewed my own code for quality and clarity.
  • Added comments to complex or tricky code sections.
  • Updated any affected documentation.
  • Included tests that validate the fix or feature.
  • Checked that related changes are merged.

@coveralls
Copy link

Coverage Status

coverage: 53.344% (+0.004%) from 53.34%
when pulling 0ed6094 on evankanderson:fix-main
into a4d5c7f on stacklok:main.

@evankanderson evankanderson merged commit 2fa96c9 into mindersec:main Oct 10, 2024
22 checks passed
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.

3 participants