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

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

Closed
2 tasks done
frederikhors opened this issue Apr 1, 2020 · 29 comments
Closed
2 tasks done

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

frederikhors opened this issue Apr 1, 2020 · 29 comments

Comments

@frederikhors
Copy link

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)
@weiznich
Copy link
Member

weiznich commented Apr 1, 2020

Basically a duplicate of #1900.

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

@weiznich weiznich closed this as completed Apr 1, 2020
@frederikhors
Copy link
Author

@weiznich thank for your answer.

Now I'm using:

[dependencies]
actix-web = "=2.0.0"
actix-rt = "=1.0.0"
chrono = { version = "=0.4.11", features = ["serde"] }
diesel = { version = "=1.4.4", features = ["postgres", "r2d2", "uuidv07", "chrono"] }
diesel_migrations = "=1.4.0"
dotenv = "=0.15.0"
env_logger = "=0.7.1"
lazy_static = "=1.4.0"
log = "=0.4.8"
r2d2 = "=0.8.8"
serde = "=1.0.105"
serde_json = "=1.0.50"
uuid = { version = "=0.8.1", features = ["serde", "v4"] }

But Cargo gives me a warning:

warning: Feature uuidv07 of package diesel has been obsolete in version 1.4.4

@weiznich
Copy link
Member

weiznich commented Apr 1, 2020

We do not say that anywhere in our code, so I'm not sure where cargo is getting this information from. You should probably rise a issue there.

@frederikhors
Copy link
Author

there where?

@weiznich
Copy link
Member

weiznich commented Apr 1, 2020

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.

@problame
Copy link

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 ?

@gaku-sei
Copy link

gaku-sei commented Jun 18, 2021

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"

@ghost
Copy link

ghost commented Jun 24, 2021

Wow this should be reopened/ a new issue created. Same problem for me, was fixed by @gaku-sei 's solution

@enokson
Copy link

enokson commented Aug 29, 2021

I just had the same issue. The issue was also resolved by @gaku-sei 's solution.

@idiotleon
Copy link

idiotleon commented Aug 29, 2021

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,
}

@idiotleon
Copy link

Other things that were helpful to me:

  1. to match order src
  2. to deserialize nullable type src:

@KodrAus
Copy link

KodrAus commented Nov 2, 2021

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.

@weiznich
Copy link
Member

weiznich commented Nov 2, 2021

@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.

@Corallus-Caninus
Copy link

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.

@Corallus-Caninus
Copy link

Corallus-Caninus commented Nov 4, 2021

I fixed with using the diesel::*::Uuid type in schema and uuid::Uuid crate in model and my application. I also had to roll diesel back to 1.4.4 and use uuidv07 feature

This is my Toml
uuid = { version = "0.8.2", features = ["v4"] }
diesel = { version = "1.4.4", features = ["postgres", "numeric", "num-integer", "num-bigint", "num-traits", "uuidv07"] }

@KodrAus
Copy link

KodrAus commented Nov 25, 2021

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.

@weiznich
Copy link
Member

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

@piscespieces
Copy link

The solution referenced above works

diesel = {version = "1.4.8", features = ["uuidv07", "r2d2", "postgres"]}

note the "uuidv07" instead of just "uuid"

@KodrAus
Copy link

KodrAus commented Apr 20, 2022

Just a heads up @weiznich I'm running through that 1.0.0 release of uuid now: uuid-rs/uuid#596

@weiznich
Copy link
Member

@KodrAus Thanks for the heads up. I've pushed #3137 to add support for uuid 1.0.0 to diesel master 🎉

@CuriousCI
Copy link

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.

@weiznich
Copy link
Member

@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.

@tadman

This comment was marked as off-topic.

@weiznich

This comment was marked as off-topic.

@jayvdb

This comment was marked as off-topic.

@weiznich

This comment was marked as off-topic.

@ashupednekar

This comment was marked as outdated.

@weiznich

This comment was marked as outdated.

@ashupednekar
Copy link

Got it, will do

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