Skip to content

pgtype: handle typed-nil driver.Valuer in array/composite codecs#2567

Merged
jackc merged 1 commit into
jackc:masterfrom
donners:fix/pgtype-array-composite-typed-nil-valuer
May 31, 2026
Merged

pgtype: handle typed-nil driver.Valuer in array/composite codecs#2567
jackc merged 1 commit into
jackc:masterfrom
donners:fix/pgtype-array-composite-typed-nil-valuer

Conversation

@donners
Copy link
Copy Markdown
Contributor

@donners donners commented May 25, 2026

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.

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.
@jackc jackc merged commit 4a3eeaf into jackc:master May 31, 2026
@jackc
Copy link
Copy Markdown
Owner

jackc commented May 31, 2026

Thanks!

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.

2 participants