sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

sqlx uses time instead of chrono

Open karuna opened this issue 1 year ago • 14 comments

Bug Description

sqlx 0.8.0

After using 0.8.0, there's an opposite of this problem: https://github.com/launchbadge/sqlx/issues/2689

Minimal Reproduction

sqlx = { version = "0.8", features = [
  "postgres",
  "runtime-tokio-rustls",
  "macros",
  "migrate",
  "json",
  "chrono",
  "uuid",
], default-features = false }

CREATE TABLE IF NOT EXISTS "users" (
  "id" uuid PRIMARY KEY DEFAULT uuid7(),
  "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
);
#[derive(Clone, Default, sqlx::FromRow)]
pub struct User {
    pub id: Uuid,
    pub created_at: DateTime<Utc>,
}

fn foo(conn: PgPool, user_id: Uuid) {
    let user = query_as!(
        User,
        r#"SELECT id, created_at FROM users WHERE users.id = $1"#,
        &user_id
    )
    .fetch_one(&conn)
    .await?;
}
153 |               let recover = query_as!(User,
    |  ___________________________^
154 | |                 r#"SELECT id, created_at FROM users WHERE users.id = $1"#,
158 | |                 &user_id
159 | |             )
    | |_____________^ the trait `From<OffsetDateTime>` is not implemented for `chrono::DateTime<Utc>`, which is required by `OffsetDateTime: Into<_>`

Info

  • SQLx version: 0.8.0
  • SQLx features enabled: "postgres", "runtime-tokio-rustls", "macros", "migrate", "json", "chrono", "uuid"
  • Database server and version: Postgres 16.3
  • Operating system: Linux
  • rustc --version: 1.80.0

karuna avatar Aug 07 '24 12:08 karuna

I've located the bug is caused by this pr https://github.com/hyperium/tonic/commit/c3be20c86e1a6dfa3523b2d77e8c503d0f5b2ce3

zier-one avatar Aug 29 '24 06:08 zier-one

And I try to fix it in https://github.com/hyperium/tonic/pull/1885#discussion_r1735674401

zier-one avatar Aug 29 '24 07:08 zier-one

fixed in #1885

zier-one avatar Aug 29 '24 14:08 zier-one