-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Try to hack around a breaking change in diesel 2.1 #3643
Try to hack around a breaking change in diesel 2.1 #3643
Conversation
I don't have access to the branch to apply the tests, anyway, here are the tests, for the #[cfg(feature = "postgres")]
#[test]
fn distinct_on_sql_literal() {
use crate::schema::users::dsl::*;
let connection = &mut connection();
diesel::sql_query(
"INSERT INTO users (name, hair_color) VALUES ('Sean', 'black'), ('Sean', NULL), ('Tess', NULL), ('Tess', NULL)",
).execute(connection)
.unwrap();
let expected_data = vec![
NewUser::new("Sean", Some("black")),
NewUser::new("Tess", None),
];
// order by with sql literal
let data: Vec<_> = users
.select(NewUser::as_select())
.order(dsl::sql::<sql_types::Bool>("name"))
.distinct_on(name)
.load(connection)
.unwrap();
assert_eq!(expected_data, data);
// order by and distinct on with sql literal
let data: Vec<_> = users
.select(NewUser::as_select())
.order(dsl::sql::<sql_types::Bool>("name"))
.distinct_on(dsl::sql::<sql_types::Bool>("name"))
.load(connection)
.unwrap();
assert_eq!(expected_data, data);
// distinct on with sql literal
let data: Vec<_> = users
.select(NewUser::as_select())
.order(name)
.distinct_on(dsl::sql::<sql_types::Bool>("name"))
.load(connection).unwrap();
assert_eq!(expected_data, data);
} I also added the failed test case to
|
@omid Thanks for providing these test cases. I've checked them and only the following is accepted on diesel 2.0.4: // order by and distinct on with sql literal
let data: Vec<_> = users
.select(NewUser::as_select())
.order(dsl::sql::<sql_types::Bool>("name"))
.distinct_on(dsl::sql::<sql_types::Bool>("name"))
.load(connection)
.unwrap();
assert_eq!(expected_data, data); The other two cases were not accepted before. I will try and see if I find a good solution to add support for that case back. |
What's left here to do? I am happy to give it a shot, to see that we can get closer to a patch release for diesel out |
The open work here is figuring out how to get all the compile tests passing. That requires changing these impls to cover the |
Okay, I got to the point where i understand the problem and the current implementation as well as the issue with overlapping implementations. I'll see if i can find the time to dig into this, since this seem rather non-trivial. |
I think I've found a solution for the overlapping impl problem: We need to generate more target implementations. Essentially permutations like these: impl<T1, T2> ValidOrderingForDistinct<DistinctOnClause<(T1, T2)>> for OrderClause<(crate::expression::operators::Asc<T1>, crate::expression::operators::Asc<T2>)> {}
impl<T1, T2> ValidOrderingForDistinct<DistinctOnClause<(T1, T2)>> for OrderClause<(crate::expression::operators::Asc<T1>, crate::expression::operators::Desc<T2>)> {}
impl<T1, T2> ValidOrderingForDistinct<DistinctOnClause<(T1, T2)>> for OrderClause<(crate::expression::operators::Desc<T1>, crate::expression::operators::Asc<T2>)> {}
impl<T1, T2> ValidOrderingForDistinct<DistinctOnClause<(T1, T2)>> for OrderClause<(crate::expression::operators::Desc<T1>, crate::expression::operators::Desc<T2>)> {}
impl<T1, T2> ValidOrderingForDistinct<DistinctOnClause<(T1, T2)>> for OrderClause<(T1, crate::expression::operators::Desc<T2>)> {}
impl<T1, T2> ValidOrderingForDistinct<DistinctOnClause<(T1, T2)>> for OrderClause<(T1, crate::expression::operators::Asc<T2>)> {}
impl<T1, T2> ValidOrderingForDistinct<DistinctOnClause<(T1, T2)>> for OrderClause<(crate::expression::operators::Desc<T1>, T2)> {}
impl<T1, T2> ValidOrderingForDistinct<DistinctOnClause<(T1, T2)>> for OrderClause<(crate::expression::operators::Asc<T1>, T2)> {} need to be generate for all supported tuple sizes. I will try to integrate that into the relevant macro next time I have some spare time. If someone else want's to try that please go on and let me know the results. |
…n diesel 2.1 This commit fixes a breaking change in diesel 2.1. We accidentally rejected queries that contained a custom expression as order and group by clause.
c496d87
to
6a0cab9
Compare
…n_with_custom_expressions Try to hack around a breaking change in diesel 2.1
This commit fixes diesel-rs#3766 by adding all the missing impls. It uses the same strategy as diesel-rs#3643 for all implementations.
This commit fixes diesel-rs#3766 by adding all the missing impls. It uses the same strategy as diesel-rs#3643 for all implementations.
This commit fixes diesel-rs#3766 by adding all the missing impls. It uses the same strategy as diesel-rs#3643 for all implementations.
cc @omid
That change is not complete yet. It misses:
DISTINCT ON (name, id) … ORDER BY name ASC, id DESC
cases.