-
-
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
Add a flag to help users better debug bad Queryable
impls
#1615
Conversation
diesel/src/deserialize.rs
Outdated
/// name -> Text, | ||
/// hair_color -> Nullable<Text>, | ||
/// created_at -> Timestamp, | ||
/// updated_at -> Timestamp, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be Nullable<Timestamp>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes good catch
/// | | ||
/// 24| / updated_at: SystemTime, | ||
/// | | ||
/// = note: expected type `users::columns::created_at` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's going on here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some generated code to assert order like this:
let users::updated_at = users::all_columns.4
That code gets a span which points at the field definition as its source location
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohhh I didn't see the order was wrong :D
use self::std::result::Result::Err; | ||
use self::std::convert::Into; | ||
|
||
Err("`#[check_types]` is only for debugging purposes".into()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that should rather panic than return a Err
, because this is clearly a programmer mistake.
(We could even think about using compile_error!
if this typechecks correctly.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, because you could have lots of code, add a column to you Queryable
struct and still want the project to compile instead of throwing 20 000 compile errors telling you that #[check_types]
is for debugging only.
/// found type `users::columns::created_at` | ||
/// ``` | ||
/// | ||
/// Keep in mind that `#[check_types]` is only for debugging purposes. The impl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should mention somewhere here that this feature needs the unstable feature and a nightly compiler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sgrif I do not see this anywhere mentioned.
Since the impl we generate is so generic, when a bad `Queryable` impl is given, the error doesn't occur until they actually try to load a query. This ends up being really non-local, and gives little to no feedback about which field is actually the problem. There is a new option called `#[check_types]` which completely changes how the impl is generated, in such a way that when the `unstable` feature is enabled the error will point at the specific field that is the problem. The actual message is the same, but where it points makes debugging much easier. This flag also generates code which validates that your fields are in the right order to match your columns. Unfortunately, we cannot have this generate an actual usable impl. Trait bounds not matching in types or where clauses will always result in an error pointing at the derive itself, which is no more helpful than where we started. For that reason, we can't actually have any usable `Row` type. So this flag is for debugging purposes only. This does not help with cases where the number of fields is incorrect.
@@ -82,6 +82,11 @@ for Rust libraries in [RFC #1105](https://github.com/rust-lang/rfcs/blob/master/ | |||
rounding issues. This is primarily to support things like `avg(int_col)`, | |||
which we define as returning `Numeric` | |||
|
|||
* `#[check_types]` has been added to help debug missing `Queryable` impls. See |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's wrong with it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're not missing, just wrong impls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I worded it this way because the message the user gets is literally "Queryable<...>
is not implemented"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense I guess
That's now basically implemented by #3359 |
Since the impl we generate is so generic, when a bad
Queryable
impl isgiven, the error doesn't occur until they actually try to load a query.
This ends up being really non-local, and gives little to no feedback
about which field is actually the problem.
There is a new option called
#[check_types]
which completely changeshow the impl is generated, in such a way that when the
unstable
feature is enabled the error will point at the specific field that is
the problem. The actual message is the same, but where it points makes
debugging much easier.
This flag also generates code which validates that your fields are in
the right order to match your columns.
Unfortunately, we cannot have this generate an actual usable impl.
Trait bounds not matching in types or where clauses will always result
in an error pointing at the derive itself, which is no more helpful than
where we started. For that reason, we can't actually have any usable
Row
type. So this flag is for debugging purposes only.This does not help with cases where the number of fields is incorrect.