pgtype: handle typed-nil driver.Valuer in array/composite codecs#2567
Merged
jackc merged 1 commit intoMay 31, 2026
Merged
Conversation
Regression introduced in v5.8.0 (1a5fa7f). The fix for jackc#2453 routed typed-nil array elements and composite fields through the NULL path by discarding the second return value of isNilDriverValuer. For value-receiver Valuers on a typed-nil receiver the helper returns (true, true) meaning "nil but Value() is safe to call" — Map.Encode honours this; the array/composite encoders were dropping it on the floor, so a column declared NOT NULL JSONB[] that previously accepted []T{nil, nil} (because T.Value() returns []byte("[]")) now fails the insert because pgx writes {NULL,NULL}. Mirrors the existing Map.Encode pattern at pgtype.go:1970: when isNil && callNilDriverValuer, dispatch through encodePlanDriverValuer instead of emitting NULL. The pointer-receiver-Valuer panic case from jackc#2453 still goes through the NULL path because isNilDriverValuer returns (true, false) for it.
Owner
|
Thanks! |
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.
Note: This proposed fix was authored by Claude Code (Opus 4.7). I have a good understanding of the problem and the aim of the fix, but don't have a deep understanding of the surrounding code. Map.Encode already handles this issue, so the fix seemed fairly well scoped in terms of mirroring that pattern.
Regression introduced in v5.8.0 (1a5fa7f). The fix for #2453 routed typed-nil array elements and composite fields through the NULL path by discarding the second return value of isNilDriverValuer. For value-receiver Valuers on a typed-nil receiver the helper returns (true, true) meaning "nil but Value() is safe to call" — Map.Encode honours this; the array/composite encoders were dropping it on the floor, so a column declared NOT NULL JSONB[] that previously accepted []T{nil, nil} (because T.Value() returns []byte("[]")) now fails the insert because pgx writes {NULL,NULL}.
Mirrors the existing Map.Encode pattern at pgtype.go:1970: when isNil && callNilDriverValuer, dispatch through encodePlanDriverValuer instead of emitting NULL. The pointer-receiver-Valuer panic case from #2453 still goes through the NULL path because isNilDriverValuer returns (true, false) for it.