Open
Description
This comment here is incorrect:
sqlx/sqlx-core/src/postgres/types/chrono/datetime.rs
Lines 79 to 81 in 2e1658e
If you have a connection set to use a non-UTC timezone you will get a response with timestamps in that timezone. After overriding the executor to use PgValueFormat::Text
for responses and adding some extra debugging code, running the following code:
let date = Utc.ymd(2020, 1, 1).and_hms(1, 1, 1);
let mut conn = pool.acquire().await?;
sqlx::query("SET TIME ZONE 'Europe/Berlin'")
.fetch_optional(&mut conn).await?;
let row: (DateTime<Utc>,) = sqlx::query_as("SELECT $1::timestamptz")
.bind(&date)
.fetch_one(&mut conn).await?;
assert_eq!(row.0, date);
The assertion failed because the timezone on the response was not taken into account
[/tmp/tmp.ErEoBwofoQ/sqlx-core-0.4.0-beta.1/src/postgres/types/chrono/datetime.rs:79] ("decode", s) = (
"decode", "2020-01-01 02:01:01+01",
)
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `2020-01-01T02:01:01Z`,
right: `2020-01-01T01:01:01Z`', src/main.rs:19:5
I can't see any way to trigger this behaviour from outside sqlx-core
since it always uses the binary format for responses, but it seems like a potential footgun to leave around in case this does someday become configurable.