Diesel: Attempting to box a query, undecipherable error

I have a struct:

#[derive(Queryable, Selectable, Identifiable, Serialize, Deserialize)]
#[diesel(table_name = probe_requests)]
pub struct ProbeRequest {
    pub id: u8,
    pub mac: [u8; 6],
    pub ssid: Option<String>,
    pub htcap: u8,
    pub rssi: u8,
    pub time_of_capture: NaiveDateTime,
    pub sniffer: Uuid,
    pub location: GeogPoint,
}

which represents the table:

diesel::table! {
    use diesel::sql_types::*;
    use diesel_geography::sql_types::*;

    probe_requests (id) {
        id -> Int8,
        mac -> Macaddr,
        ssid -> Nullable<Varchar>,
        htcap -> Int4,
        rssi -> Int4,
        time_of_capture -> Timestamp,
        sniffer -> Uuid,
        location -> Geography,
    }
}

which i am attempting to write a boxed query for, in order to use another struct's function to transform it into a filter based on its attributes, which come from query params for a microservice of mine.

Despite following Diesel docs on into_boxed(), cargo still errors out regarding the trait FromSqlRow<_, Pg> not being satisfied.

It can be caused by the following code:

    let res = probe_requests::table
        .select(ProbeRequest::as_select())
        .into_boxed()
        .limit(10)
        .load::<ProbeRequest>(conn)
        .expect("Couldn't select probe request using provided filter");

causing the following enormous two errors:

error[E0277]: the trait bound `diesel::expression::select_by::SelectBy<probe_request_microservice::models::probereq::ProbeRequest, Pg>: load_dsl::private::CompatibleType<probe_request_microservice::models::probereq::ProbeRequest, Pg>` is not satisfied
    --> src/controllers/probereq.rs:49:31
     |
49   |         .load::<ProbeRequest>(conn)
     |          ----                 ^^^^ the trait `load_dsl::private::CompatibleType<probe_request_microservice::models::probereq::ProbeRequest, Pg>` is not implemented for `diesel::expression::select_by::SelectBy<probe_request_microservice::models::probereq::ProbeRequest, Pg>`
     |          |
     |          required by a bound introduced by this call
     |
     = help: the trait `load_dsl::private::CompatibleType<U, DB>` is implemented for `diesel::expression::select_by::SelectBy<U, DB>`
     = note: required for `BoxedSelectStatement<'_, SelectBy<ProbeRequest, Pg>, FromClause<table>, Pg>` to implement `LoadQuery<'_, _, probe_request_microservice::models::probereq::ProbeRequest>`
     = note: the full type name has been written to '/home/gio/dev/multilang/shomer/probeReqRust/target/debug/deps/probe_request_microservice-b11822eb9c380e5a.long-type-12760721144934163047.txt'
note: required by a bound in `diesel::RunQueryDsl::load`
    --> /home/gio/.cargo/registry/src/github.com-1ecc6299db9ec823/diesel-2.0.4/src/query_dsl/mod.rs:1499:15
     |
1499 |         Self: LoadQuery<'query, Conn, U>,
     |               ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `RunQueryDsl::load`



error[E0277]: the trait bound `probe_request_microservice::models::probereq::ProbeRequest: FromSqlRow<_, Pg>` is not satisfied
    --> src/controllers/probereq.rs:49:31
     |
49   |         .load::<ProbeRequest>(conn)
     |          ----                 ^^^^ the trait `FromSqlRow<_, Pg>` is not implemented for `probe_request_microservice::models::probereq::ProbeRequest`
     |          |
     |          required by a bound introduced by this call
     |
     = help: the following other types implement trait `FromSqlRow<ST, DB>`:
               <(T1, T0) as FromSqlRow<(ST1, Untyped), __DB>>
               <(T1, T2, T0) as FromSqlRow<(ST1, ST2, Untyped), __DB>>
               <(T1, T2, T3, T0) as FromSqlRow<(ST1, ST2, ST3, Untyped), __DB>>
               <(T1, T2, T3, T4, T0) as FromSqlRow<(ST1, ST2, ST3, ST4, Untyped), __DB>>
               <(T1, T2, T3, T4, T5, T0) as FromSqlRow<(ST1, ST2, ST3, ST4, ST5, Untyped), __DB>>
               <(T1, T2, T3, T4, T5, T6, T0) as FromSqlRow<(ST1, ST2, ST3, ST4, ST5, ST6, Untyped), __DB>>
               <(T1, T2, T3, T4, T5, T6, T7, T0) as FromSqlRow<(ST1, ST2, ST3, ST4, ST5, ST6, ST7, Untyped), __DB>>
               <(T1, T2, T3, T4, T5, T6, T7, T8, T0) as FromSqlRow<(ST1, ST2, ST3, ST4, ST5, ST6, ST7, ST8, Untyped), __DB>>
             and 23 others
     = note: required for `BoxedSelectStatement<'_, SelectBy<ProbeRequest, Pg>, FromClause<table>, Pg>` to implement `LoadQuery<'_, _, probe_request_microservice::models::probereq::ProbeRequest>`
     = note: the full type name has been written to '/home/gio/dev/multilang/shomer/probeReqRust/target/debug/deps/probe_request_microservice-b11822eb9c380e5a.long-type-12760721144934163047.txt'
note: required by a bound in `diesel::RunQueryDsl::load`
    --> /home/gio/.cargo/registry/src/github.com-1ecc6299db9ec823/diesel-2.0.4/src/query_dsl/mod.rs:1499:15
     |
1499 |         Self: LoadQuery<'query, Conn, U>,
     |               ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `RunQueryDsl::load`

Is this related to the postGIS types? I am honestly flabbergasted.

Heads-up: I have no experience in this area.


Have you tried #[diesel(check_for_backend(YourBackendType))] as per the docs? It may clarify if the GIS type is the problematic field.

1 Like

I was using diesel 2.0.4 previously, since i started this project in May 16. Bumping the diesel version up to 2.1.0 and adding the backend check did show me the error was in my struct type definitions (Int8 and Int4 aren't supposed to be u8, as the Diesel Postgres Types gist shows). Changing it to

pub struct ProbeRequest {
    pub id: i64,
    pub mac: [u8; 6],
    pub ssid: Option<String>,
    pub htcap: i32,
    pub rssi: i32,
    pub time_of_capture: NaiveDateTime,
    pub sniffer: Uuid,
    pub location: GeogPoint,
}

Solved the issue, and now the into_boxed() call works without compiler errors.

For some reason, while i was trying to "triangulate" the error by removing fields from the struct, i found out that the Uuid and mac fields couldn't be present at the same time, otherwise it would output the same error as before. I thought that this finickiness could indicate that postGIS was responsible, since it has a lot of datatypes.

I will now re-implement all of the code i stripped in order to (unsuccessfully) find out what caused the error, and if nothing else indicating that it still persists shows up i will close the question.

Yes, the problem was caused by the usage of incorrect types in my struct, which made the struct itself incompatible with the defined schema. Many thanks to check_for_backend and you for pointing me towards Diesel 2.1.0 and using it.

1 Like