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

Trait bound NaiveDateTime: sqlx::Decode<'_, sqlx::Any> is not satisfied #2636

Open
canac opened this issue Jul 20, 2023 · 14 comments
Open

Trait bound NaiveDateTime: sqlx::Decode<'_, sqlx::Any> is not satisfied #2636

canac opened this issue Jul 20, 2023 · 14 comments
Labels

Comments

@canac
Copy link

canac commented Jul 20, 2023

Bug Description

In trying to migrate my project from sqlx 0.6.3 to 0.7.1, I'm getting a compile error with try_get on an AnyRow with chrono::NaiveDateTime (code snippet below).

error[E0277]: the trait bound `NaiveDateTime: sqlx::Decode<'_, sqlx::Any>` is not satisfied

Maybe I'm missing something, but it appears that #2039 removed those impls without adding them back.

$ git show -p b5312c3b6f8e34e757d1441216b6b34a18afd14b | grep NaiveDateTime
-impl_any_type!(chrono::NaiveDateTime);
-impl_any_encode!(chrono::NaiveDateTime);
-impl_any_decode!(chrono::NaiveDateTime);
@@ -4,10 +4,10 @@ use chrono::{DateTime, Datelike, Local, NaiveDate, NaiveDateTime, NaiveTime, Tim
     DateTime, Duration, FixedOffset, Local, NaiveDate, NaiveDateTime, Offset, TimeZone, Utc,
     DateTime, Local, NaiveDate, NaiveDateTime, NaiveTime, Offset, SecondsFormat, TimeZone, Utc,

Was this an accidental breakage or is there something I can change in my code to get it working again?

Minimal Reproduction

use sqlx::any::AnyRow;
use sqlx::{FromRow, Result, Row};

struct Message {
    pub id: i32,
    pub timestamp: chrono::NaiveDateTime,
}

impl FromRow<'_, AnyRow> for Message {
    fn from_row(row: &AnyRow) -> Result<Self> {
        Ok(Self {
            id: row.try_get("id")?,
            timestamp: row.try_get("timestamp")?,
        })
    }
}

Info

  • SQLx version: v0.7.1
  • SQLx features enabled: ["any", "chrono", "postgres", "sqlite"]
  • Database server and version: (Postgres / SQLite)
  • Operating system: macOS
  • rustc --version: v1.71.0
@canac canac added the bug label Jul 20, 2023
@kekonn
Copy link

kekonn commented Jul 28, 2023

I have the same issue with chrono::DateTime<Utc>. Changing the version in cargo.toml back to 0.6 fixes the compile errors.

My flags:

[dependencies.sqlx]
version = "0.7"
features = ["default", "chrono", "postgres", "mysql", "runtime-tokio-rustls", "any"]

@gilgabo
Copy link

gilgabo commented Sep 6, 2023

The same issue here migrating from 0.6.3 version to 0.7.1. I'm getting both error for DateTime attributes :

  • the trait sqlx::Decode<'_, sqlx::Any> is not implemented for chrono::DateTime<Utc>
  • the trait Type<sqlx::Any> is not implemented for chrono::DateTime<Utc>

Current flags (with sqlx version 0.6.3):

# DB dependencies
sqlx = { version = "0.6.3", features = [ "runtime-tokio-rustls", "postgres", "sqlite", "any", "chrono", "time" ] }
chrono = { version = "0.4.24", features = ["serde"] }

@kekonn
Copy link

kekonn commented Oct 18, 2023

This issue persists in 0.7.2

@gilgabo
Copy link

gilgabo commented Dec 22, 2023

Same bug / issue in version 0.7.3 (this implementation is working with sqlx < 0.7.x):
error[E0277]: the trait bound chrono::DateTime<Utc>: sqlx::Decode<'_, sqlx::Any> is not satisfied

# ---- from Cargo-toml -----
sqlx = { version = "0.7.3", features = [ "runtime-tokio-rustls", "postgres", "sqlite", "any", "chrono", "time" ] }
chrono = { version = "0.4.31", features = ["serde"] }
// ----- from model struct ------
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use sqlx::FromRow;
use utoipa::ToSchema;

/// Foo struct
#[derive(FromRow, Serialize, Deserialize, ToSchema, Debug)]
#[cfg_attr(test, derive(Clone, Default, PartialEq))]
pub struct Foo {
    /// foo internal id
    pub foo_id: i64,
    /// foo text value
    pub foo_text: String,
    /// foo numeric value
    pub foo_number: i64,
    /// foo inserted timestamp
    pub foo_create_ts: DateTime<Utc>,
    /// foo updated timestamp
    pub foo_update_ts: DateTime<Utc>,
}

error[E0277]: the trait bound `chrono::DateTime<Utc>: sqlx::Decode<'_, sqlx::Any>` is not satisfied
   --> src\***\*****.rs:7:10
    |
7   | #[derive(FromRow, Serialize, Deserialize, ToSchema, Debug)]
    |          ^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
8   | #[cfg_attr(test, derive(Clone, Default, PartialEq))]
9   | pub struct Foo {
    |            ^^^
note: required by a bound in `AccessDataLayerTrait::find_one_by`
// ----- from repository -----
    async fn get_foo_by_id(&self, foo_id_value: i64) -> Result<Foo, DataAccessError> {
		// ... more code here ..

        let query_result = self
            .access_data_layer
            .find_one_by(FIND_BY_ID_STMT, parameters)
            .await;
		
		// ... more code here ..
	}

error[E0277]: the trait bound `chrono::DateTime<Utc>: sqlx::Decode<'_, sqlx::Any>` is not satisfied
   --> src\***\*****.rs:115:14
    |
115 |             .find_one_by(FIND_BY_ID_STMT, parameters)
    |              ^^^^^^^^^^^ the trait `sqlx::Decode<'_, sqlx::Any>` is not implemented for `chrono::DateTime<Utc>`
    |
    = help: the following other types implement trait `sqlx::Decode<'r, DB>`:
              <chrono::DateTime<Utc> as sqlx::Decode<'r, Postgres>>
              <chrono::DateTime<Utc> as sqlx::Decode<'r, Sqlite>>
note: required for `Foo` to implement `for<'r> sqlx::FromRow<'r, sqlx::any::AnyRow>`

Do you suggest any workaround or solution for this issue?

@oscarAppd2c
Copy link

I am experiencing the same issue with version 0.7.2.

@javid2c
Copy link

javid2c commented Jan 4, 2024

Hello, is there any update on this ticket? it has been open since July, it would be great to know at least if this issue is going to be resolved or not, and an ETA if possible.
Kind regards

@Leo-Cerna
Copy link

Hello friend, do you have an estimate to look into this ticket soon??!! It would help me a lot to be able to update the library version!!

@kareemmahlees
Copy link

Any updates on this ?!

@crs117
Copy link

crs117 commented Apr 26, 2024

Seems like I must be doing something wrong if only the few of us in this thread seem to be running into this. As noted it seems like the behavior works with 6.3 fine but the 7.0 version made some drastic changes.

If this is not a major issue, how are other people working around this issue?

@ohuu
Copy link

ohuu commented May 13, 2024

I'm seeing the same thing.

@holmofy
Copy link

holmofy commented Aug 3, 2024

I have the same problem

@kareemmahlees
Copy link

Issue persists in 0.8.0 :(

@gilgabo
Copy link

gilgabo commented Aug 5, 2024

Our workaround to avoid these breaking changes was remove AnyPool implementation / references and split it between Sqlite and Postgres implementations based on Rust profiles... does not make any sense, it was a lot of rework but now it's working 🫠

@StarStarJ
Copy link

@abonander Could you please verify that the removal of this feature was intended and sqlx will not add it back?

I think it's better to be clear about this issue than keep ppl using old versions of sqlx because they wait for a version that is compatible in this regard again.

Thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests