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

Traits Expression and NotNull are not implemented by Uuid #881

Closed
m-r-r opened this Issue May 1, 2017 · 4 comments

Comments

Projects
None yet
2 participants
@m-r-r

m-r-r commented May 1, 2017

Hello,

My model contains several structs which need to derive both Insertable and Queryable.

Here is one of those structs:

#[derive(PartialEq, Eq, Debug, Clone, Queryable, AsChangeset, Associations)]
#[belongs_to(User, foreign_key="user_id")]
pub struct SyncKey {
    pub id: i32,
    pub user_id: i32,
    pub name: Option<String>,
    pub key: Uuid,
    pub created_at: NaiveDateTime,
    pub last_used: Option<NaiveDateTime>,
}

The compilation fails with the following error messages:

error[E0277]: the trait bound `uuid::Uuid: diesel::Expression` is not satisfied
  --> src/models.rs:27:1
   |
27 | #[derive(PartialEq, Eq, Debug, Clone, Queryable, AsChangeset, Associations)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `uuid::Uuid`
   |
   = note: required because of the requirements on the impl of `diesel::Expression` for `&uuid::Uuid`
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<uuid::Uuid>` for `&uuid::Uuid`
   = note: this error originates in a macro outside of the current crate

error[E0277]: the trait bound `uuid::Uuid: diesel::Expression` is not satisfied
  --> src/models.rs:27:1
   |
27 | #[derive(PartialEq, Eq, Debug, Clone, Queryable, AsChangeset, Associations)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `uuid::Uuid`
   |
   = note: required because of the requirements on the impl of `diesel::Expression` for `&'update uuid::Uuid`
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<uuid::Uuid>` for `&'update uuid::Uuid`
   = note: this error originates in a macro outside of the current crate

error[E0277]: the trait bound `uuid::Uuid: diesel::Expression` is not satisfied
  --> src/models.rs:27:1
   |
27 | #[derive(PartialEq, Eq, Debug, Clone, Queryable, AsChangeset, Associations)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `uuid::Uuid`
   |
   = note: required because of the requirements on the impl of `diesel::Expression` for `&uuid::Uuid`
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<uuid::Uuid>` for `&uuid::Uuid`
   = note: this error originates in a macro outside of the current crate

This is only an excerpt of the full error message, the full error message is here.

I'm using diesel 0.12 with features postgres, chrono and uuid.
I created a gist with the full source code of my model and the SQL schema: https://gist.github.com/m-r-r/5571d1da8cea8ea52759c5fb9bbb7072

I don't understand why I get this error: according to the documentation, the type Uuid does implement NotNull and AsExpression… Maybe I'm not using the macros correctly?

@sgrif

This comment has been minimized.

Member

sgrif commented May 1, 2017

Can you ensure that there is only one version of uuid in your Cargo.lock? Diesel 0.12.0 doesn't support UUID 0.5.0 which is likely your problem. https://github.com/diesel-rs/diesel/blob/v0.12.0/diesel/Cargo.toml#L25

@m-r-r

This comment has been minimized.

m-r-r commented May 1, 2017

Thanks for responding so fast!
That's the first time I open an issue and someone replies literally 2 minutes later :-)

Can you ensure that there is only one version of uuid in your Cargo.lock?

If I am not mistaken, there is one version of uuid in my project :

$ grep uuid     
 "uuid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "uuid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
name = "uuid"
"checksum uuid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7cfec50b0842181ba6e713151b72f4ec84a6a7e2c9c8a8a3ffc37bb1cd16b231"

I use the same version requirement as diesel (I copied it from Diesel's Cargo.toml):

uuid = ">= 0.2.0, < 0.5.0"
@sgrif

This comment has been minimized.

Member

sgrif commented May 1, 2017

Remove the use uuid::Uuid; lines from your table! invocations. That should fix your problem.

@m-r-r

This comment has been minimized.

m-r-r commented May 1, 2017

Remove the use uuid::Uuid; lines from your table! invocations. That should fix your problem.

It works ! Thanks for your help :-)

@m-r-r m-r-r closed this May 1, 2017

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