fix: resolve #2642 — Query macro documentation understates lack of nullability checking on bind parameters#4291
Open
chinhkrb113 wants to merge 1 commit into
Conversation
… lack of nullability checking on bind parameters Fixes transact-rs#2642 Signed-off-by: ChinhLee <76194645+chinhkrb113@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
query!family of macros validates the types of bind parameters against the database's inferred parameter types, but it does not verify whether a bound value's nullability is compatible with the target column's NOT NULL constraint. As a result, passing aNone/NULLvalue for a non-nullable column compiles successfully and only fails at runtime with a database constraint violation. This is a known limitation (databases generally report bind parameters as nullable, and the macro has no way to associate a parameter with a specific column constraint at compile time), but it is not currently documented, which surprised the user. We should add an explicit "Nullability" / "Limitations" note to the macro documentation explaining this behavior so users understand that null-checking is only performed on output columns, not on input bind parametersFixes #2642
Changes
src/macros/mod.rsWhy
src/macros/mod.rs: Thequery!family of macros validates the types of bind parameters against the database's inferred parameter types, but it does not verify whether a bound value's nullability is compatible with the target column's NOT NULL constraint. As a result, passing aNone/NULLvalue for a non-nullable column compiles successfully and only fails at runtime with a database constraint violation. This is a known limitation (databases generally report bind parameters as nullable, and the macro has no way to associate a parameter with a specific column constraint at compile time), but it is not currently documented, which surprised the user. We should add an explicit "Nullability" / "Limitations" note to the macro documentation explaining this behavior so users understand that null-checking is only performed on output columns, not on input bind parameters.