Skip to content

Conversation

vonzshik
Copy link
Contributor

Fixes #5820

@vonzshik vonzshik requested a review from roji as a code owner September 16, 2024 13:29
@NinoFloris
Copy link
Member

#5645 🙃

@vonzshik
Copy link
Contributor Author

vonzshik commented Sep 26, 2024

#5645 🙃

Sadly, it's probably not going to fix the bug :(
The issue isn't us not resetting position on exception (that was the first thing I tried) but due to the way the code is structured we never actually expect a non-breaking non-pg exception in NextResult, which leads to DataRow never being consumed, so we lose protocol sync.

@NinoFloris
Copy link
Member

Right, so the approach I took there was to actually log an error for the failed parameter (in line with us ignoring returnvalue or parameters with a non matching name) and leave it at that, so I'm not sure how we would be able to get an exception up into NextResult at all.

Of course whether we want to log + ignore the offending param vs terminate + consume is something to discuss.

@vonzshik
Copy link
Contributor Author

Ah, I missed the part around SetValue. Yeah, OK, that does fix the issue (though I still think throwing is much better compared to logging as user code can interpret whatever output parameter has by default as an actual value and has no way to react + not everyone has logging enabled).

@NinoFloris
Copy link
Member

user code can interpret whatever output parameter has by default as an actual value and has no way to react

That's a good argument. I don't like that part in general about the output param flow, there is no way to feed back status to users (unless we add a ton of api surface to parameters).

Direction = ParameterDirection.InputOutput,
Value = 1
});
Assert.ThrowsAsync<InvalidCastException>(cmd.ExecuteNonQueryAsync);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my mental picture, what was the reason we would throw here originally? Don't we skip over parameters/outputs that we haven't defined in the collection?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a weird behavior we have in that we try to populate unmatched parameters with unmatched values. We have #2252 open to investigate and potentially remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified the test to also have out param in case we someday remove that behavior

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vonzshik vonzshik force-pushed the 5820-output-param-cast-exception-not-break-protocol-sync branch from de69a96 to 5d1a004 Compare October 13, 2024 04:25
@vonzshik vonzshik enabled auto-merge (squash) October 13, 2024 04:25
@vonzshik vonzshik merged commit 764bfea into main Oct 13, 2024
14 checks passed
@vonzshik vonzshik deleted the 5820-output-param-cast-exception-not-break-protocol-sync branch October 13, 2024 04:31
vonzshik added a commit that referenced this pull request Oct 13, 2024
vonzshik added a commit that referenced this pull request Oct 13, 2024
vonzshik added a commit that referenced this pull request Oct 13, 2024
@vonzshik
Copy link
Contributor Author

Backported to 8.0.5 via 2e914cc, 7.0.9 via 81b4166, 6.0.13 via 459f455

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

If one query fails, the next query will also fail in the same connection.
2 participants