You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
error[E0277]: the trait bound *const str: diesel::deserialize::FromSql<diesel::sql_types::Array<diesel::sql_types::Text>, diesel::pg::Pg> is not satisfied
#2434
Closed
2 tasks done
jaredforth opened this issue
Jun 12, 2020
· 2 comments
active toolchain
----------------
stable-x86_64-unknown-linux-gnu (default)
rustc 1.41.1 (f3e1a954d 2020-02-24)
Diesel:1.4.3
Database: PostgreSQL 12.2
Operating System: Ubuntu 18.04 (Windows Subsystem for Linux)
Feature Flags
diesel:{ version = "1.4.3", features = ["postgres"] }
Problem Description
What are you trying to accomplish?
I am trying to call the load() function to return a Vec of a struct that implements Queryable.
Instead of compiling, running cargo build gives me error[E0277]: the trait bound *const str: diesel::deserialize::FromSql<diesel::sql_types::Arraydiesel::sql_types::Text, diesel::pg::Pg> is not satisfied.
There are two issues that have described similar problems to mine, but neither are quite the same.
The first is #330, and the issue was simply that the user was trying to use a Nullable<Integer> SQL value with a model that had an i32 type instead of an Option<i32>.
The second is #2011, with the issue being that the struct in models.rs had a different order than the table! macro in schema.rs.
Neither of these solutions apply to my problem, which is why I suspect it might be a bug.
Steps to reproduce
The load() function is called with the following code:
use actix::{Message,Handler};use std::io;usecrate::models;usecrate::db::DbExecutor;use diesel::prelude::*;pubstructWebpages;implMessageforWebpages{typeResult = io::Result<Vec<models::Webpage>>;}implHandler<Webpages>forDbExecutor{typeResult = io::Result<Vec<models::Webpage>>;fnhandle(&mutself, _:Webpages, _:&mutSelf::Context) -> Self::Result{usecrate::schema::webpage::dsl::*;let w = match webpage.load::<models::Webpage>(&self.conn){Ok(items) => items,Err(_) => {returnErr(io::Error::new(io::ErrorKind::Other,"Database error"));}};Ok(w)}}
The DbExecutor is just a connection to Postgres, but I am including it here:
/// Database [SyncArbiter](https://actix.rs/book/actix/sec-6-sync-arbiter.html)/// with a connection field to PostgrespubstructDbExecutor{conn:PgConnection}/// Create Sync ActorimplActorforDbExecutor{typeContext = SyncContext<Self>;}/// Implement new `DbExecutor` with a live Postgres connectionimplDbExecutor{pubfnnew(db_url:&str) -> DbExecutor{let conn = PgConnection::establish(db_url).expect(&format!("Error connecting to {}", db_url));// Run database migrations
diesel_migrations::run_pending_migrations(&conn).unwrap();DbExecutor{
conn
}}}
Your struct implementing Queryable uses a Option<String> as 15. field (images). This type is not compatible with the Nullable<Array<Text>> returned by your query at this position.
Setup
Versions
Running
rustup show
gives:1.4.3
Feature Flags
{ version = "1.4.3", features = ["postgres"] }
Problem Description
What are you trying to accomplish?
I am trying to call the
load()
function to return aVec
of a struct that implementsQueryable
.Instead of compiling, running
cargo build
gives meerror[E0277]: the trait bound
*const str: diesel::deserialize::FromSql<diesel::sql_types::Arraydiesel::sql_types::Text, diesel::pg::Pg>is not satisfied
.There are two issues that have described similar problems to mine, but neither are quite the same.
The first is #330, and the issue was simply that the user was trying to use a
Nullable<Integer>
SQL value with a model that had ani32
type instead of anOption<i32>
.The second is #2011, with the issue being that the struct in
models.rs
had a different order than thetable!
macro inschema.rs
.Neither of these solutions apply to my problem, which is why I suspect it might be a bug.
Steps to reproduce
The
load()
function is called with the following code:The
DbExecutor
is just a connection to Postgres, but I am including it here:My
Webpage
model inmodels.rs
is as follows:My
schema.rs
webpage table is as follows:My
up.sql
for the migration that generated the schema is:In the code above, the model, schema, and SQL all have the same order, and every value that is not specified as
NOT NULL
is wrapped in anOption<T>
.Checklist
closed if this is not the case)
The text was updated successfully, but these errors were encountered: