Skip to content

fix: let a later --state-values-set assignment replace a value of another type - #2880

Merged
yxxhero merged 1 commit into
helmfile:mainfrom
lbarrosby:fix/state-values-set-type-conflict
Nov 8, 2026
Merged

yxxhero merged 1 commit into
helmfile:mainfrom
lbarrosby:fix/state-values-set-type-conflict

Conversation

@lbarrosby

Copy link
Copy Markdown
Contributor

maputil.Set panics when a --state-values-set / --state-values-set-string assignment descends into a key that already holds a value of another type:

e.g. --state-values-set foo=1,foo.bar=2 ends in panic: unexpected type: 1(int64) from keyArg.getMap.

Same for foo=1,foo[0]=2, foo.bar=1,foo[0]=2, foo[0]=1,foo.bar=2 and foo[0]=1,foo[0].bar=2.

setAssignment was written to return an error instead of panicking on malformed input, but these assignments are well formed, so the panic comes from keyArg.getMap, indexedKeyArg.getArray and indexedKeyArg.getMap. This change makes the later assignment replace the earlier value, consistent with how repeated flags already overwrite earlier values (message=first then message=second).

Test: TestSet_LaterAssignmentReplacesValueOfAnotherType covers the five cases above. It panics on main and passes with the fix.

$ go test ./pkg/maputil/ -run TestSet_LaterAssignment   # before the fix
--- FAIL: TestSet_LaterAssignmentReplacesValueOfAnotherType (0.00s)
panic: unexpected type: 1(int64) [recovered, repanicked]
FAIL	github.com/helmfile/helmfile/pkg/maputil

$ go test ./pkg/maputil/ && go vet ./pkg/maputil/   # after
ok  	github.com/helmfile/helmfile/pkg/maputil	0.402s

…ther type

maputil.Set panicked with "unexpected type" when an assignment descended
into a key that already held a value of another type, e.g.
--state-values-set foo=1,foo.bar=2 or foo=1,foo[0]=2. The later assignment
now replaces the earlier value, the same way repeated flags already
overwrite earlier values.

Signed-off-by: Lucas Barros <[email protected]>
@yxxhero

yxxhero commented Nov 8, 2026

Copy link
Copy Markdown
Member

@lbarrosby cool. could you ever try to use vscode-helmfile?

@yxxhero
yxxhero merged commit 1aed894 into helmfile:main Nov 8, 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