-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix: Decode and Encode derives (#1031) #2940
fix: Decode and Encode derives (#1031) #2940
Conversation
Hey @benluelo, seems like some checks failed because there is a unused import which is treated as an error. Can you fix that? I would love to see this merged as this issue bugs me since a while. Happy to help out as well :) |
It's fixed in |
I opened up a PR to your branch with the rebase on main :) |
@abonander FYI: Rebase is merged, checks are green :). |
@abonander Can you merge this :)? |
Don't want to bother but I would really love to see this merged :) Anything that is missing that I can assist with? |
@abonander last try before I stop bothering you: Is there anything missing or anything I can help with to get this merged? I would not like to see the PR dying again as @benluelo already reopened that and the value that this PR adds is huge (at least for me, I ran into this "bug" multiple times). |
I am going to second that this is a fairly huge PR in terms of usability and would like to see this merged. Furthermore, the lack of response for a month for such a big project is concerning. |
@abonander any update? |
Strictly speaking, this appears to be a potential breaking change as discussed by @jplatte in #1031 (comment) because it changes lifetime obligations for field types: If I understand correctly, the previous bounds would potentially allow, e.g. a type that only implemented Would this realistically affect anybody in practice? It seems unlikely, but unless we're confident that this is not a breaking change because code relying on the previous behavior wouldn't have compiled anyways, then it has to wait for 0.8.0. |
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 would also like to see a regression test that can be demonstrated to be fixed by this.
Actually no, I wasn't talking about lifetimes. I was talking about something like this: #[derive(sqlx::Encode)]
struct Foo<T> {
field: sqlx::types::Json<T>,
} which currently works because it generates a This is an actual regression in functionality, but IMO warranted because otherwise private field types leak into the public trait implementation. It's also how virtually all other derives work. See also |
That is a much better point than I was trying to make. Adding a |
@benluelo we are now merging breaking changes, so if you could rebase and fix the conflict that'd be great. |
39bb514
to
56d5f08
Compare
56d5f08
to
e5cfa8e
Compare
squashed and rebased, should be good to go (barring any issues I missed post-rebase) |
// add db type for impl generics & where clause | ||
for type_param in &mut generics.type_params_mut() { | ||
type_param.bounds.extend::<[TypeParamBound; 2]>([ | ||
parse_quote!(for<'decode> ::sqlx::decode::Decode<'decode, ::sqlx::Postgres>), |
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.
Why is this now a higher-order bound instead of Decode<'r, _>
like before?
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.
honestly, i wrote this so long ago, i don't recall any of the reasoning behind my changes. happy to change this though
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.
If it works, I think 'r
without the for<>
makes more sense. If not, I'd be curious why.
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.
It may have been to get around an "implementation is not general enough" error. People complain about those from time to time.
This change is what I was thinking about in this comment BTW #2940
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.
Which "this comment"? GitHub doesn't highlight anything for me when clicking that link.
And I'm pretty sure the for<'decode>
makes the impl less general and can't possibly fix any errors.
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.
The comment I @-mention'd you in above.
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.
Ahh, so you agree with keeping the 'r
if possible, right?
} | ||
|
||
let (impl_generics, _, where_clause) = generics.split_for_impl(); | ||
generics.params.push(parse_quote!('r)); |
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 wonder what the idea behind this is (I know it existed before already).
// add db type for impl generics & where clause | ||
for type_param in &mut generics.type_params_mut() { | ||
type_param.bounds.extend::<[TypeParamBound; 2]>([ | ||
parse_quote!(for<'encode> ::sqlx::encode::Encode<'encode, ::sqlx::Postgres>), |
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.
Same here.
} | ||
|
||
let (impl_generics, _, where_clause) = generics.split_for_impl(); | ||
generics.params.push(parse_quote!('q)); |
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.
Ditto.
Is there a update to this as this is a blocking issue for a lot of people that want to use composite types in postgres that have null values. If there is anything I can do to help let me know. @abonander |
Reopening #2329