Skip to content

sha2 = "0.6.0" dependency causes "The trait postgres::types::FromSql is not implemented for chrono::NaiveDateTime" #289

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

Closed
dprien opened this issue Sep 13, 2017 · 4 comments

Comments

@dprien
Copy link

dprien commented Sep 13, 2017

The following project won't compile unless the sha2 dependency is removed or changed to version "0.5.3" instead (remove Cargo.lock & target/ before recompiling).

Cargo.toml

[package]
name = "postgres_chrono_test"
version = "0.1.0"

[dependencies]
postgres = { version = "*", features = ["with-chrono"] }
chrono = "*"
sha2 = "0.6.0"

src/main.rs

extern crate chrono;
extern crate postgres;
fn main() {
    let conn = postgres::Connection::connect("postgres://test@localhost:5432", postgres::TlsMode::None).unwrap();
    for row in &conn.query("SELECT foo FROM widgets WHERE bar = 1", &[]).unwrap() {
        let _: chrono::NaiveDateTime = row.get(0);
    }
}

$ cargo check

error[E0277]: the trait bound `chrono::NaiveDateTime: postgres::types::FromSql` is not satisfied
 --> src/main.rs:6:44
  |
6 |         let _: chrono::NaiveDateTime = row.get(0);
  |                                            ^^^ the trait `postgres::types::FromSql` is not implemented for `chrono::NaiveDateTime`

I'm not sure what's going on here, if I hit a basic limitation of Rust when multiple versions of the same crate are pulled in or if this is specific to the postgres crate. Any explanation would be much appreciated.

@sfackler
Copy link
Owner

The wildcard version constraints on postgres and chrono state that your crate works with every version of postgres and chrono that have ever been released. Cargo is selecting postgres 0.14.1 and chrono 0.4 which aren't compatible.

If you select the versions of postgres and chrono you actually want, it seems like it runs into rust-lang/cargo#4488. :(

@dprien
Copy link
Author

dprien commented Sep 13, 2017

The wildcard version constraints on postgres and chrono state that your crate works with every version of postgres and chrono that have ever been released.

Well, I did not know that. Turns out I totally misunderstood wildcard versions. Thanks for the explanation.

@dprien dprien closed this as completed Sep 13, 2017
@sfackler
Copy link
Owner

I just released a version of postgres-protocol that should work around that cargo bug.

@dprien
Copy link
Author

dprien commented Sep 13, 2017

Great! Thank you.

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

No branches or pull requests

2 participants