-
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(postgres): PgHasArrayType is not implemented for Vec<i64> #2617
Conversation
caused by launchbadge#2086 closes launchbadge#2611 seems like launchbadge#2086 fixed issue described by @Wopple by making that block of code unreachable. Not as it was stated in > Problem: PgHasArrayType was checking the application's postgres feature > Solution: only check the library's postgres feature after checking https://doc.rust-lang.org/std/macro.cfg.html > `cfg!`, unlike `#[cfg]`, does not remove any code and only evaluates > to true or false. For example, all blocks in an if/else expression > need to be valid when `cfg!` is used for the condition, regardless of > what `cfg!` is evaluating. so to my understanding it would be `true` anyway in @woople scenario
Have you verified that this actually fixes your problem? I can't see how that would be possible. The thing you are reverting did make sense, since it does a cfg check for the sqlx-macro crate's features, instead of the features of the crate in which the derive is expanded. |
@jplatte I did verify that it fixes my problem:
if you have another idea how this can be fixed/workarounded then please feel free to reproduce based on steps from #2611 |
Oh, I think I get it. You don't actually intend to ever have arrays of |
So, the problem is that the The idiomatic thing would probably be to never generate the impl from the Type derive and introduce a separate derive macro for the array trait. But that would be a breaking change, and I'm sure people are already relying on the Type macro generating this impl. I think the best solution for sqlx 0.7 is to allow people to opt out of the array trait impl. |
Yeah, @jplatte's assessment is correct. It appears a non-generic impl will throw an error if its Theoretically, Unfortunately, just straight reverting this change will break other cases where the derive is successfully compiled and being used, so I'm unable to accept this PR as-is. However, I'm going to get working on a fix straight away, as I do agree this is a problem. That's most likely just going to involve an attribute that allows one to opt out of the array derive. For 0.8 I may consider separating |
Complete guess here, but would something like this help? #[derive(sqlx::Type)]
#[sqlx(transparent)]
pub struct ScriptHash(pub i64);
pub type ScriptHashes = Vec<ScriptHash>; |
hello @Wopple, thanks for reaching out. Your proposal indeed compiles for
I've tried it with slight modification running pub struct ScriptHash(pub i64);
#[derive(PartialEq)]
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
-#[cfg_attr(feature = "sqlx", sqlx(transparent))]
pub struct ScriptHashes(pub Vec<i64>);
impl Display for ScriptHash {
@@ -91,7 +90,7 @@ impl Serialize for ScriptHashes {
{
let mut seq = serializer.serialize_seq(Some(self.0.len()))?;
for element in &self.0 {
- seq.serialize_element(&ScriptHash(*element))?;
+ seq.serialize_element(element)?;
}
seq.end()
} and indeed it compiles now 🙇 The best part is that to my recollection I experimented with it, before bothering ppl here. Not sure why I abandoned this approach. Perhaps I hit errors caused by unrelated breaking change (linked below), that - in frustration - I assumed to be related ... sqlx/examples/postgres/transaction/src/main.rs Lines 14 to 17 in afb6b10
=== Looks like above patch would work with |
caused by #2086
closes #2611
context
seems like #2086 fixed issue described by @Wopple by making that block of code unreachable. Not as it was stated in
rationale for reverting that change
after checking https://doc.rust-lang.org/std/macro.cfg.html
so to my understanding it would be
true
anyway in @woople scenario