Skip to content

fix(values): preserve nil values when chart default is empty map#31644

Merged
banjoh merged 6 commits intohelm:mainfrom
banjoh:em/fix-nil-values
Jan 31, 2026
Merged

fix(values): preserve nil values when chart default is empty map#31644
banjoh merged 6 commits intohelm:mainfrom
banjoh:em/fix-nil-values

Conversation

@banjoh
Copy link
Copy Markdown
Contributor

@banjoh banjoh commented Dec 12, 2025

What this PR does / why we need it:

Only delete nil user values when overriding a non-nil chart default. When chart has empty map or no default for a key, preserve user's nil.

Scenario Result
User sets baz: ~, chart has baz: "value" Key deleted
User sets baz: ~, chart has empty map {} Nil preserved
User sets baz: ~, chart has baz: ~ Nil preserved

Fixes #31643

Special notes for your reviewer:

If applicable:

  • this PR contains user facing changes (the docs needed label should be applied if so)
  • this PR contains unit tests
  • this PR has been tested for backwards compatibility

Only delete nil user values when overriding a non-nil chart default.
When chart has empty map or no default for a key, preserve user's nil.

| Scenario | Result |
|----------|--------|
| User sets `baz: ~`, chart has `baz: "value"` | Key deleted |
| User sets `baz: ~`, chart has empty map `{}` | Nil preserved |
| User sets `baz: ~`, chart has `baz: ~` | Nil preserved |

Fixes helm#31643

Signed-off-by: Evans Mungai <mbuevans@gmail.com>
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 12, 2025
@banjoh banjoh added the bug Categorizes issue or PR as related to a bug. label Dec 12, 2025
@banjoh banjoh marked this pull request as draft December 12, 2025 16:34
Signed-off-by: Evans Mungai <mbuevans@gmail.com>
@banjoh banjoh marked this pull request as ready for review December 12, 2025 17:01
Signed-off-by: Evans Mungai <mbuevans@gmail.com>
robertsirc
robertsirc previously approved these changes Dec 17, 2025
Copy link
Copy Markdown
Member

@robertsirc robertsirc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@robertsirc robertsirc added the Has One Approval This PR has one approval. It still needs a second approval to be merged. label Dec 17, 2025
// otherwise the values are coalesced.
CoalesceTables(dst, src)

is.Equal("Ishmael", dst["name"], "Unexpected name: %s", dst["name"])
Copy link
Copy Markdown
Member

@gjenkins8 gjenkins8 Dec 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be okay to split this refactoring of conditional logic to assert into a new PR. Why assert (IMHO) is much better for test readability, it is difficult here to review any logic changes (due to any changes in the code logic)

if !ok {
t.Fatal("Address went away.")
}
t.Run("case 1", func(t *testing.T) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this and the below t.Run(... separate test cases?

(but see my comment below about creating a new PR for these refactoring changes)

Co-authored-by: George Jenkins <gvjenkins@gmail.com>
Signed-off-by: Evans Mungai <mbuevans@gmail.com>
banjoh added 2 commits January 7, 2026 12:58
Signed-off-by: Evans Mungai <mbuevans@gmail.com>
Signed-off-by: Evans Mungai <mbuevans@gmail.com>
@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 7, 2026
@banjoh
Copy link
Copy Markdown
Contributor Author

banjoh commented Jan 7, 2026

@gjenkins8 I removed all the test refactoring changes and left the unit test validating the reported bug

@KrzysztofDziankowski
Copy link
Copy Markdown

I have verified the fix for my use case and it appears to work.
Could this pull request be included in the next Helm 3.20.x release?

Copy link
Copy Markdown
Contributor

@TerryHowe TerryHowe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@banjoh banjoh merged commit 5b78ee8 into helm:main Jan 31, 2026
5 checks passed
@banjoh banjoh deleted the em/fix-nil-values branch January 31, 2026 13:03
@chojnack
Copy link
Copy Markdown
Contributor

chojnack commented Feb 5, 2026

Could you please merge this into 3.20 branch too? We could build that ourselves then for our testing.

@joejulian joejulian added this to the 4.1.2 milestone Feb 11, 2026
@joejulian joejulian added needs-pick Indicates that a PR needs to be cherry-picked into the next release candidate. and removed Has One Approval This PR has one approval. It still needs a second approval to be merged. labels Feb 11, 2026
@scottrigby scottrigby removed this from the 4.1.2 milestone Mar 11, 2026
@scottrigby scottrigby added this to the 4.1.3 milestone Mar 11, 2026
@scottrigby scottrigby added v3 port complete For completed v2->v3 ports picked Indicates that a PR has been cherry-picked into the next release candidate. and removed needs-pick Indicates that a PR needs to be cherry-picked into the next release candidate. labels Mar 11, 2026
Y0-L0 added a commit to Y0-L0/helm that referenced this pull request Mar 28, 2026
Three test cases that cover the regression scenarios introduced
by the helm#31644 nil preservation fix:

- subchart default nils should be cleaned up
when parent doesn't set those keys (helm#31919)
- user-supplied null should erase subchart defaults (helm#31919)
- subchart default nil should not shadow global values via pluck (helm#31971)

Tests are expected to fail until the regression is fixed.
@Y0-L0 Y0-L0 mentioned this pull request Mar 28, 2026
2 tasks
Y0-L0 added a commit to Y0-L0/helm that referenced this pull request Mar 28, 2026
Three test cases that cover the regression scenarios introduced
by the helm#31644 nil preservation fix:

- subchart default nils should be cleaned up
when parent doesn't set those keys (helm#31919)
- user-supplied null should erase subchart defaults (helm#31919)
- subchart default nil should not shadow global values via pluck (helm#31971)

Tests are expected to fail until the regression is fixed.
Y0-L0 added a commit to Y0-L0/helm that referenced this pull request Mar 28, 2026
Three test cases that cover the regression scenarios introduced
by the helm#31644 nil preservation fix:

- subchart default nils should be cleaned up
when parent doesn't set those keys (helm#31919)
- user-supplied null should erase subchart defaults (helm#31919)
- subchart default nil should not shadow global values via pluck (helm#31971)

Tests are expected to fail until the regression is fixed.
Y0-L0 added a commit to Y0-L0/helm that referenced this pull request Mar 28, 2026
Three test cases that cover the regression scenarios introduced
by the helm#31644 nil preservation fix:

- subchart default nils should be cleaned up
when parent doesn't set those keys (helm#31919)
- user-supplied null should erase subchart defaults (helm#31919)
- subchart default nil should not shadow global values via pluck (helm#31971)

Tests are expected to fail until the regression is fixed.
Y0-L0 added a commit to Y0-L0/helm that referenced this pull request Mar 30, 2026
Three test cases that cover the regression scenarios introduced
by the helm#31644 nil preservation fix:

- subchart default nils should be cleaned up
when parent doesn't set those keys (helm#31919)
- user-supplied null should erase subchart defaults (helm#31919)
- subchart default nil should not shadow global values via pluck (helm#31971)

Tests are expected to fail until the regression is fixed.

Signed-off-by: Johannes Lohmer <jojo.dev@lohmer.com>
Y0-L0 added a commit to Y0-L0/helm that referenced this pull request Apr 2, 2026
Three test cases that cover the regression scenarios introduced
by the helm#31644 nil preservation fix:

- subchart default nils should be cleaned up
when parent doesn't set those keys (helm#31919)
- user-supplied null should erase subchart defaults (helm#31919)
- subchart default nil should not shadow global values via pluck (helm#31971)

Tests are expected to fail until the regression is fixed.

Signed-off-by: Johannes Lohmer <jojo.dev@lohmer.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Categorizes issue or PR as related to a bug. picked Indicates that a PR has been cherry-picked into the next release candidate. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. v3 port complete For completed v2->v3 ports

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in map values merging in helm v4

8 participants