Skip to content

fix: resolve #2642 — Query macro documentation understates lack of nullability checking on bind parameters#4291

Open
chinhkrb113 wants to merge 1 commit into
transact-rs:mainfrom
chinhkrb113:improve/quality/document-that-nullability-is-not-checked
Open

fix: resolve #2642 — Query macro documentation understates lack of nullability checking on bind parameters#4291
chinhkrb113 wants to merge 1 commit into
transact-rs:mainfrom
chinhkrb113:improve/quality/document-that-nullability-is-not-checked

Conversation

@chinhkrb113
Copy link
Copy Markdown

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 a None/NULL value 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

Fixes #2642

Changes

  • src/macros/mod.rs

Why

src/macros/mod.rs: 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 a None/NULL value 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.

… lack of nullability checking on bind parameters

Fixes transact-rs#2642

Signed-off-by: ChinhLee <76194645+chinhkrb113@users.noreply.github.com>
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.

Query macro documentation understates lack of nullability checking on bind parameters

1 participant