Skip to content

issue #892 - #1623

Open
BenYang12 wants to merge 2 commits into
go-playground:masterfrom
BenYang12:#892-BenYang12
Open

issue #892#1623
BenYang12 wants to merge 2 commits into
go-playground:masterfrom
BenYang12:#892-BenYang12

Conversation

@BenYang12

Copy link
Copy Markdown

Fixes Or Enhances for issue #892

When a custom type converter returns nil, validation currently fails before a callback registered with RegisterValidationCtx(..., true) can even inspect the context or accept the value. My change lets nil-enabled callbacks run on the resulting reflect.Invalid value, including values returned by ValidatorValuer and plain nil inputs.

The validation loop checks the nil opt-in for each subsequent validator. Validators without that opt-in still fail for invalid values without being called. Error construction avoids reflection panics and retains nil type/value metadata.

Regression tests cover callback invocation and context propagation, acceptance/rejection, typed and converted nil inputs, pointer converters, AND/OR chains, aliases, omission tags, conditional built-ins, and error metadata.

  • Tests exist or have been written that cover this particular change.

Validation

Verified commit 369ef5447f99afb020bfa84dbf6907940846fd30:

  • go test -count=1 -race -covermode=atomic ./... passes; main package coverage is 96.9%.
  • golangci-lint run passes with the CI-pinned v2.13.1: 0 issues.
  • git diff --check upstream/master...HEAD passes; both changed Go files are gofmt-clean.
  • The new regression tests fail against the unchanged upstream validator.go at dfe35cf8317892133dfe31e36054dcbf36aab604, confirming the missing callback behavior.

Unresolved v10 compatibility question

I made this intentionally a draft pending maintainer guidance. The change also allows already nil-enabled built-ins (required_*, excluded_*, and skip_unless) to run on invalid values. As a result, some converted-nil inputs that previously failed unconditionally now pass when the condition permits absence. Custom nil-enabled callbacks can now receive an invalid reflect.Value and must handle it safely.

@go-playground/validator-maintainers

@BenYang12
BenYang12 requested a review from a team as a code owner September 5, 2026 19:45
@BenYang12
BenYang12 marked this pull request as draft September 5, 2026 19:47
@BenYang12
BenYang12 marked this pull request as ready for review September 5, 2026 19:51
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.

1 participant