-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Fix NULL handling for non-pointer struct sql.Scanner fields #7671
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
base: master
Are you sure you want to change the base?
Conversation
|
Handle NULL scanning for struct Adjusts Key Changes• Updated Affected Areas• This summary was automatically generated by @propel-code-bot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a bug where non-pointer struct types implementing sql.Scanner were not receiving Scan(nil) calls for NULL database values. The fix adds logic to distinguish between three cases: pointer-type fields (keep nil), fields in nil embedded pointer structs (skip to preserve nil state), and standalone non-pointer scanner fields (call Scan(nil) for proper NULL handling).
Key Changes:
- Introduced
isNilFieldPathhelper function to detect fields within nil embedded pointer structs - Added conditional logic to call
Scan(nil)for non-pointer scanner fields when receiving NULL values - Added comprehensive test coverage for the NULL handling scenario with a custom scanner type
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
schema/field.go |
Adds isNilFieldPath helper and updates struct scanner setter to distinguish between pointer fields, embedded nil struct fields, and non-pointer scanners, ensuring Scan(nil) is called appropriately |
tests/scanner_valuer_test.go |
Adds TestScannerHandlesNullForNonPointerField test and extraSettings/NullScannerModel types to verify non-pointer scanner fields receive Scan(nil) for NULL values |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Non-pointer struct `Scanner` types were not receiving `Scan(nil)` for NULL database values due to an early return that was added to preserve `nil` state for embedded pointer structs. This fix distinguishes between: - Pointer-type fields: keep `nil` - Fields in `nil` embedded pointer structs: skip to preserve `nil` state - Standalone struct scanners: call `Scan(nil)` for proper NULL handling Fixes go-gorm#7234 Signed-off-by: Aofei Sheng <[email protected]>
Scan(nil) for non-pointer struct scanners on NULL values
What did this pull request do?
Non-pointer struct
Scannertypes were not receivingScan(nil)for NULL database values due to an early return that was added to preservenilstate for embedded pointer structs. This fix distinguishes between:nilnilembedded pointer structs: skip to preservenilstateScan(nil)for proper NULL handlingUser Case Description
Fixes #7234