fix(sqlite): correctly infer nullability for INTEGER PRIMARY KEY in RETURNING#4323
Open
at264939-ctrl wants to merge 2 commits into
Open
fix(sqlite): correctly infer nullability for INTEGER PRIMARY KEY in RETURNING#4323at264939-ctrl wants to merge 2 commits into
at264939-ctrl wants to merge 2 commits into
Conversation
Author
|
Is there no one here for review? |
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.
fixes #4322. This is a fix for a regression introduced in 0.9.0.
After upgrading to sqlx 0.9.0, many users noticed that INSERT ... RETURNING queries on INTEGER PRIMARY KEY columns started returning Option instead of T, which broke a lot of code that expects a simple i64. I traced this down to commit 69ee0df from PR #4088.
The issue is that in sqlx-sqlite/src/statement/handle.rs, column_nullable was changed to return None for rowid aliases. This forces the logic to fall back to the bytecode simulation in explain.rs, which relies on PRAGMA table_info. In SQLite, this pragma returns notnull=0 for INTEGER PRIMARY KEY columns because they can be passed as NULL during an insert. However, in any actual result set, these columns are never NULL.
To fix this, I updated root_block_columns in explain.rs to include the pk column from table_info so the VM simulation can properly identify these rowid aliases and mark them as non-nullable. I also updated handle.rs to return Some(false) instead of None for these cases to provide a more accurate initial inference. Finally, I adjusted a few existing tests in explain.rs that were previously asserting these columns as nullable. I've verified the fix with integration tests and it correctly restores the expected i64 behavior