Skip to content

fix: return the default from get when a parent value is nil - #2877

Merged
yxxhero merged 1 commit into
helmfile:mainfrom
lbarrosby:fix/get-default-through-nil
Nov 6, 2026
Merged

yxxhero merged 1 commit into
helmfile:mainfrom
lbarrosby:fix/get-default-through-nil

Conversation

@lbarrosby

Copy link
Copy Markdown
Contributor

With foo: left empty in a values file (so foo is null), {{ .Values | get "foo.bar" "default" }} fails the render with:

unexpected type(<nil>) of value for key "bar": it must be either map[string]any or any struct

The docs say get returns the default when the path is not found, and that is what happens when foo is missing altogether. In get, a nil parent fell into the struct branch, which returns an error without looking at the default. This adds a nil case that returns the default when one was passed. Without a default it still returns a noValueError, so get keeps failing and getOrNil keeps returning nil.

Tested with a new TestGetWithDefaultThroughNilValue (fails on main), go test ./pkg/tmpl/ and go vet ./pkg/tmpl/ pass.

`get "foo.bar" "default" .Values` failed with "unexpected type(<nil>)"
when foo exists but is null (for example `foo:` with nothing after it in
a values file), instead of returning the default like it does when foo is
missing.

Signed-off-by: Lucas Barros <[email protected]>
@yxxhero
yxxhero merged commit 400d91d into helmfile:main Nov 6, 2026
17 checks passed
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