Repository navigation
fix(config): make flattening deterministic for duplicate keys - #2298
WitteShadovv wants to merge 1 commit into
Conversation
When a config file defines the same option both nested and flattened,
e.g. {"core": {"devMode": true}, "core/devMode": false}, flattenMap
iterated over the map in random order, so the value in use changed
between restarts.
Iterate over the keys in sorted order. A flattened key sorts after its
nested parent ("core" < "core/devMode"), so the flattened spelling
consistently takes precedence.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
When a config file defines the same option both nested and flattened, e.g.
{"core": {"devMode": true}, "core/devMode": false},flattenMapiterated over the map in Go's random order, so the value in use changed between restarts. This happens easily when config files with different spellings are merged.This iterates over the keys in sorted order. A flattened key sorts after its nested parent (
core<core/devMode), so the flattened spelling consistently takes precedence.Testing: added
TestFlattenDuplicateKeys, which fails reliably without the fix;go test ./base/config/andgo vetpass, andservice/sync(the other user ofFlatten) buildsSummary by CodeRabbit