-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
left_join
incorrectly compiling if additional joins are done afterwards
#1459
Comments
I actually don't know if we can fix this until disjointness based on associated types lands. We need to change this impl:
to be these two impls:
I need to think about this more to come up with a way to fix this today. |
I have the same issue. CREATE TABLE "integrations" (
"id" Integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
"label" Character Varying ( 100 ) NOT NULL UNIQUE,
"field_z" Text [] NOT NULL
);
CREATE TABLE "user" (
"id" Integer GENERATED ALWAYS AS IDENTITY,
"name" Character Varying( 128 ) NOT NULL UNIQUE,
"integration" Integer NOT NULL REFERENCES integrations(id),
PRIMARY KEY ( "id" )
);
CREATE TABLE "params1" (
"user_id" Integer NOT NULL REFERENCES users(id) PRIMARY KEY,
"field_x" Boolean NOT NULL
);
CREATE TABLE "params2" (
"user_id" Integer NOT NULL REFERENCES users(id) PRIMARY KEY,
"field_y" Boolean NOT NULL
);
CREATE TABLE user_tokens (
"token" Character Varying( 64 ) NOT NULL,
"user_id" Integer NOT NULL REFERENCES users(id),
PRIMARY KEY ( "token" )
); #[derive(Debug, Queryable)]
pub struct User {
pub id: i32,
pub field_x: bool,
pub field_y: bool,
pub field_z: Vec<String>,
}
let query = schema::user_tokens::table
.inner_join(
schema::users::table
.inner_join(schema::integrations::table)
.left_join(schema::params1::table)
.left_join(schema::params2::table),
)
.select((
schema::user_tokens::user_id,
schema::params1::field_x,
schema::params2::field_y,
schema::integrations::field_z,
))
.filter(schema::user_tokens::token.eq(token));
let user = query.first::<User>(&db()?); This compiles even though there is no guarantee that there is a params1 that matches the user. As a temporary workaround if this can't be fixed easily, I'd rather the database call fails or even panics than randomly set my booleans to I've tried to reverse the order of the inner and left joins, but that didn't change anything. |
Digging into it, it seems the workaround would be: impl FromSql<sql_types::Bool, Pg> for bool {
fn from_sql(bytes: Option<&[u8]>) -> deserialize::Result<Self> {
Ok(not_none!(bytes)[0] != 0)
}
} Why was the choice made to have an |
Isn't this a duplicate of #2001 ? |
Yes that's a duplicate of #2001 |
Reported via gitter. This query compiles successfully:
It should fail to compile unless
.nullable
has been called onrevision::hash
. Reversing the order of the join calls causes this code to fail to compile as it shouldThe text was updated successfully, but these errors were encountered: