Skip to content

sqlx uses time instead of chrono #3412

Closed

Description

@karuna

Bug Description

sqlx 0.8.0

After using 0.8.0, there's an opposite of this problem: #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

Activity

  1. CommanderStorm commented on Aug 7, 2024

    @CommanderStorm
    Contributor

    Hi.
    I tried to reproduce this, but cannot:
    image
    image

    Could you try producing a minimal reproducible example?
    Without this, helping you is basically impossible.

    Here is my MRE, assuming that the typo in the sqlx veryion above is a typo (otherwise upgrate do 0.8 and be happy that your issue is fixed ^^)
    bin.tar.gz

  2. CommanderStorm commented on Aug 7, 2024

    @CommanderStorm
    Contributor

    Note that I also cannot reproduce this in 0.7...
    Idk what you did..

  3. karuna commented on Aug 7, 2024

    @karuna
    Author

    I guess something else activating time

  4. karuna commented on Aug 7, 2024

    @karuna
    Author

    Here's my cargo tree output.
    I see some depends on time

    tree.txt

  5. karuna commented on Aug 7, 2024

    @karuna
    Author

    Yup, can confirm something is activating time. Here's my mre:
    ajep.tar.gz

  6. abonander commented on Aug 7, 2024

    @abonander
    Collaborator
  7. karuna commented on Aug 8, 2024

    @karuna
    Author

    @abonander I thought explicitly disabling time on features is enough.
    I'll wait for #3383 then.

  8. abonander commented on Aug 9, 2024

    @abonander
    Collaborator

    It's not just another crate depending on time. It's another crate that depends on sqlx and enables the time feature, due to Cargo's feature unification.

    In your case, that appears to be tower-sessions-sqlx-store:

    ├── tower-sessions-sqlx-store v0.13.0
    │   ├── async-trait v0.1.81 (proc-macro) (*)
    │   ├── rmp-serde v1.3.0 (*)
    │   ├── sqlx v0.8.0 (*)
    │   ├── thiserror v1.0.62 (*)
    │   ├── time v0.3.36 (*)
    │   └── tower-sessions-core v0.12.2 (*)
    

    We can confirm this by looking at their Cargo.toml: https://github.com/maxcountryman/tower-sessions-stores/blob/cecfba06e7ebc031d59d51a5926e19b3bc2c2d0d/sqlx-store/Cargo.toml#L23

    I would consider this their bug due to them hardcoding the time feature instead of allowing you to choose.

  9. abonander commented on Aug 9, 2024

    @abonander
    Collaborator
  10. cemoktra commented on Aug 20, 2024

    @cemoktra
    Contributor

    In the meantime, you can use type overrides to work around this: https://docs.rs/sqlx/latest/sqlx/macro.query.html#force-a-differentcustom-type

    This is pretty annoying. We need to update to 0.8.x due to the advisory in 0.7.x but we have to change hundreds of queries due to that change. I sthere any easier approach?

    Or can the advisory be fixed in a 0.7.5?

  11. abonander commented on Aug 20, 2024

    @abonander
    Collaborator

    I included mitigation advice in the advisory for a reason. If you take reasonable precautions it's unlikely to be exploitable.

    For that same reason, I'm not inclined to spend my limited bandwidth backporting the fix. We have no LTS policy for releases and I don't want people to get the impression that we do.

    If the danger was more immediate, it'd be a different story, but no other database lib has even bothered to publish an advisory yet, and I know at least Diesel is likely affected as well because they've done their own extensive audit and they're considering backporting the changes.

    Otherwise, you could instead find and deal with the dependency that's enabling the time feature unconditionally. There's unlikely to be many candidates.

  12. jdu commented on Aug 29, 2024

    @jdu

    In the meantime, you can use type overrides to work around this: https://docs.rs/sqlx/latest/sqlx/macro.query.html#force-a-differentcustom-type

    Is there a way to do this on an INSERT/UPDATE, I can't seem to see what the syntax would look like in that case.

  13. cemoktra commented on Aug 29, 2024

    @cemoktra
    Contributor

    In the meantime, you can use type overrides to work around this: https://docs.rs/sqlx/latest/sqlx/macro.query.html#force-a-differentcustom-type

    Is there a way to do this on an INSERT/UPDATE, I can't seem to see what the syntax would look like in that case.

    Usually you just bind your value: value as _

  14. karuna commented on Sep 3, 2024

    @karuna
    Author

    let's wait for this maxcountryman/tower-sessions-stores#46 to be released

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions