fix: prefer codec over driver.Valuer for typed-nil in array/composite encoding - #2621
Open
waterWang wants to merge 1 commit into
Open
fix: prefer codec over driver.Valuer for typed-nil in array/composite encoding#2621waterWang wants to merge 1 commit into
waterWang wants to merge 1 commit into
Conversation
… encoding When a typed-nil value in an array or composite field implements driver.Valuer, the array and composite codecs bypass the element type's registered Codec and directly call encodePlanDriverValuer. This is incorrect when the type has a registered Codec that should handle nil values (typically encoding as SQL NULL). Fix: replace the encodePlanDriverValuer shortcut with PlanEncode, which naturally gives precedence to the Codec's PlanEncode before falling back to driver.Valuer encoding. This ensures that types with both a Codec and driver.Valuer use the Codec's nil handling. Fixes jackc#2611
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.
Description
When a typed-nil value in an array or composite field implements
driver.Valuer, the array and composite codecs bypass the element type's registered Codec and directly callencodePlanDriverValuer. This is incorrect when the type has a registered Codec that should handle nil values (typically encoding as SQL NULL).This was introduced in #2567.
Fix
Replace the
encodePlanDriverValuershortcut withPlanEncode, which naturally gives precedence to the Codec'sPlanEncodebefore falling back to driver.Valuer encoding. This ensures that types with both a Codec anddriver.Valueruse the Codec's nil handling.Changes
pgtype/array_codec.go(text + binary encode paths): Replaced directencodePlanDriverValuercall withPlanEncode+ caching byelemType(same pattern as the non-nil path)pgtype/composite.go\** (text + binary builder): Replaced directencodePlanDriverValuerwithPlanEncode(with fallback toencodePlanDriverValuer` if nil)Fixes #2611