-
Notifications
You must be signed in to change notification settings - Fork 3
fix: avoid trailing Z when converting RFC3339 timestamps in UTC for postgres #168
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
base: main
Are you sure you want to change the base?
Conversation
| // to avoid problems when used for recovery_target_time | ||
| func ConvertToPostgresFormat(timestamp string) string { | ||
| formatWithoutZ := func(t time.Time) string { | ||
| formatted := t.Format("2006-01-02 15:04:05.000000Z07:00") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, questions. In the ParseTargetTime function in pkg/types/time.go , we make use of pq.ParseTimestamp().
Why not use pq.FormatTimestamp() here, regardless of input formats?
Moreover, why not validate the input in this function? We validated RFC3339 and RFC3339Micro, but standalone, this function, given "foo", will assume it's a valid timestamp and just return it.
|
There is an E2E test exercising the conversion function: cloudnative-pg/cloudnative-pg#8981 |
b43eeb3 to
0af1ca3
Compare
|
Regarding I tested it and it still outputs So using Additionally, So we need Go's Regarding validation: You're right that given However, I've pushed two additional commits that improve this:
If we want stricter validation (return error for invalid input), that would be a breaking API change. We could consider it for a future version. |
|
Thanks Marco, that makes good sense. Good changes. |
|
Hey @jsilvela! Merry Christmas and Happy New Year to you too! This PR has been expanded to address a related consistency issue discovered while investigating. The original fix avoids the trailing Now both functions consistently treat RFC3339-like timestamps without timezone as UTC, and Related PRs: cloudnative-pg/cloudnative-pg#8937 and cloudnative-pg/plugin-barman-cloud#700 |
Signed-off-by: Jaime Silvela <[email protected]>
Use +00:00 instead of +00 for UTC timezone offset to maintain consistency with non-UTC timestamps which use the full offset format (e.g., +03:00). Signed-off-by: Marco Nenciarini <[email protected]>
Add support for converting timestamps in RFC3339-like format without timezone (e.g., "2023-07-06T08:00:39") to PostgreSQL format. This format is accepted by ParseTargetTime in pkg/types/time.go but was previously passed through unchanged, causing PostgreSQL to reject the timestamp due to the 'T' separator. Signed-off-by: Marco Nenciarini <[email protected]>
RFC3339-like timestamps without timezone (e.g., "2006-01-02T15:04:05") are now interpreted as UTC and output with explicit +00:00 suffix. This ensures consistency between: - ParseTargetTime (used by barman-cloud for backup selection) - ConvertToPostgresFormat (used for PostgreSQL recovery_target_time) Both functions now treat such timestamps as UTC, avoiding potential timezone mismatches where backup selection and recovery could target different points in time. Signed-off-by: Marco Nenciarini <[email protected]>
Closes #167
Avoid the trailing Z in RFC3339 / ISO 8601 in UTC zone, which does not play as a recovery target time.