diesel: the trait bound uuid::Uuid: diesel::Expression is not satisfied

Versions

  • Rust: 1.42.0
  • Diesel: 1.4.4
  • Database: Postgres 12
  • Operating System: Win 10

Cargo.toml

diesel = { version = "=1.4.4", features = ["postgres", "r2d2", "uuid", "chrono"] }
diesel_migrations = "=1.4.0"
...
uuid = { version = "=0.8.1", features = ["serde", "v4"] }

Problem Description

What are you trying to accomplish?

Use uuid with diesel with no problems.

What is the expected output?

It works.

What is the actual output?

the trait bound uuid::Uuid: diesel::Expression is not satisfied

Are you seeing any additional errors?

Nope.

I saw:

But still problems, why?

Checklist

  • I have already looked over the issue tracker for similar issues.
  • This issue can be reproduced on Rust’s stable channel. (Your issue will be closed if this is not the case)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 26 (9 by maintainers)

Most upvoted comments

Second @problame’s issue, the following dependencies and features don’t work:

diesel = {version = "1.4.4", features = ["chrono", "postgres", "r2d2", "uuid"]}
uuid = "0.8.2"

But this does:

diesel = {version = "1.4.4", features = ["chrono", "postgres", "r2d2", "uuidv07"]}
uuid = "0.8.2"

Basically a duplicate of https://github.com/diesel-rs/diesel/issues/1900.

(You need to use the uuidv07 feature to make this work.)

FWIW, I am using diesel 1.4.5 with uuid 0.8.1 and adding the uuidv07 feature just fixed the problem for me. Is there a cfg! in diesel 1.4.5 that still uses uuidv07 ?

@KodrAus Thanks for reaching out here ❤️ There are a few common uuid related issues in diesel:

  • Mixing up diesel::sql_types::Uuid and uuid::Uuid. This is basically an issue with users ignoring our documentation, which explicitly states that types from diesel::sql_types cannot hold values and shouldn’t be used anywhere in your “model”. This is something that we can only improve on diesels side.
  • For the 1.4.x release series there seems to be some confusion about which feature flag enables support for uuid. There is the “uuid” and the “uuid_v07” feature, where the former enables the support for uuid < 0.7 and the later for the 0.7 and 0.8 releases. As of today I personally believe it was a mistake to name that features that way, but unfortunately there is no way to reverse that. Fortunately, the next diesel release will be 2.0, so we can fix that there. It’s already better on the master branch, where we’ve just dropped support for uuid < 0.7 and only have single uuid feature left. Maybe I will also rename the features for third party crates to indicate the version numbers in a better way, so that this does not happen anymore. So in the end, again that’s something to fix on diesels side.

That written: The uuid integration in diesel is really simple, as it’s only a few lines of code. As long as the two function we are using are not changed in an incompatible way there is really not much maintained burden here. Having a stable uuid 1.0 release should really help there.

@CuriousCI We don’t plan to release any additional 1.4.x release at this point in time as we just don’t have the resources to maintain more than one diesel version in parallel.

Shouldn’t the 1.4.x release support uuid 1.0.0 too? I’m currently facing some issues with Rocket.rs as it relies on diesel 1.4, but it’s uuid feature is implemented for uuid 1.0.0. I’ll open an issue to add 2.0.0 support for diesel in Rocket, but until then I have to monkey patch the problem: I downgraded to uuid 0.8, and manually implemented Rocket’s traits.

@KodrAus Thanks for the heads up. I’ve pushed https://github.com/diesel-rs/diesel/pull/3137 to add support for uuid 1.0.0 to diesel master 🎉

Just a heads up @weiznich I’m running through that 1.0.0 release of uuid now: https://github.com/uuid-rs/uuid/pull/596

@KodrAus Thanks for that information. Yes that’s the plan to update the dependency to 1.0 before doing the diesel 2.0 release.

Thanks for the details @weiznich!

Yeh, there’s no way those Uuid::from_fields and Uuid::as_bytes will ever change. So your next release is going to be 2.0? Depending on how you want to go, if you wanted to consolidate your uuid features to just its 1.0 you should be safe depending on uuid’s 1.0.0-alpha.1 release. We’re treating it as already stable, and will follow up with a 1.0.0 proper once it’s proven itself. Cargo should happily consider 1.0.0-alpha.1 and 1.0.0 as semver compatible.

I’m getting the trait ‘diesel::Expression’ is not implemented for ‘uuid::Uuid’ on 1.4.8 and uuid 8.2 with feature uuid in diesel.

Is there a trait impl we could add over in uuid that would clear all this up? We’re currently working on stabilizing uuid so hopefully can smooth things out for diesel one way or another.

tl;dr Well, I used uuid::Uuid, instead of diesel::sql_type::uuid, which quenched this error.

More background: Unfortunately, none works for me. Here is my Cargo.toml.

[dependencies]
actix-cors = "0.5.4"
actix-rt = "1.1.1"
actix-service = "1.0.6"
actix-web = "3.3.2"
bcrypt = "0.10.1"
chrono = { version = "0.4.19", features = ["serde"] }
derive_more = "0.99.11"
diesel = {version = "1.4.4", features = ["chrono", "postgres", "r2d2", "uuidv07"]}
diesel_migrations = "1.4.0"
dotenv = "0.15.0"
env_logger = "0.9.0"
# for heroku rust buildpack
libsqlite3-sys = { version = "0.22.2", features = ["bundled"] }
failure = "0.1.8"
futures = "0.3.12"
jsonwebtoken = "7.2.0"
log = "0.4.14"
serde = "1.0.123"
serde_derive = "1.0.123"
serde_json = "1.0.62"
# uuid = { version = "0.8.1", features = ["serde", "v4"]}
uuid = "0.8.2"

The error reads:

the trait bound `diesel::sql_types::Uuid: diesel: Expression` is not satisfied required because of the requirements on the impl of `AsExpression<diesel::sql_types::Uuid>`

Here is where went wrong:

#[derive(Insertable)] // <- here
#[table_name = "history_signin"]
pub struct InsertableDTOHistorySignIn{
    pub user_id: Uuid,
    pub timestamp_signin: NaiveDateTime,
}

In the issue tracker of whichever tool is giving you this warning. So if it’s cargo itself then here: https://github.com/rust-lang/cargo/, if it’s some custom subcommand in then in their issue tracker.