-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fully overrides default slice fields of config (#4001) #6163
Conversation
Codecov ReportBase: 92.06% // Head: 92.06% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #6163 +/- ##
=======================================
Coverage 92.06% 92.06%
=======================================
Files 219 219
Lines 13242 13252 +10
=======================================
+ Hits 12191 12201 +10
Misses 828 828
Partials 223 223
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing the issue! Overall LGTM. Just one nit regarding tests
// To address this we zeroes every slice before unmarshalling unless user provided slice is nil. | ||
func zeroesSliceHookFunc() mapstructure.DecodeHookFuncValue { | ||
return func(from reflect.Value, to reflect.Value) (interface{}, error) { | ||
if from.Kind() == reflect.Slice && from.IsNil() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Len() == 0? No need to re-initialize if empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If user provides empty list in the config explicitly then we zeroes the default value of the field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bogdandrutu do you mean if both source and destination are 0 then we should just return?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets start with this:
nil != initialized and len 0
foo:
foo: []
What is the behavior we want in these cases? Please document them somewhere, in order for me to understand if the implementation is ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping on this.
62b2fba
to
ca970c1
Compare
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
ca970c1
to
9213f8d
Compare
@bogdandrutu @dmitryax please can you take a look? All comments are fixed. |
mapstructure library doesn't override full slice during unmarshalling. Origin issue: mitchellh/mapstructure#74 (comment) To address this we empty every slice before unmarshalling unless user provided slice is nil.
9213f8d
to
cfebf0b
Compare
@dmitryax fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR looks ok to me, will merge once @bogdandrutu's comments have been addressed
// To address this we zeroes every slice before unmarshalling unless user provided slice is nil. | ||
func zeroesSliceHookFunc() mapstructure.DecodeHookFuncValue { | ||
return func(from reflect.Value, to reflect.Value) (interface{}, error) { | ||
if from.Kind() == reflect.Slice && from.IsNil() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bogdandrutu do you mean if both source and destination are 0 then we should just return?
} | ||
|
||
if to.CanSet() && to.Kind() == reflect.Slice { | ||
to.Set(reflect.MakeSlice(reflect.SliceOf(to.Type().Elem()), 0, 0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why 0 capacity? I think default in golang is 8?
// To address this we zeroes every slice before unmarshalling unless user provided slice is nil. | ||
func zeroesSliceHookFunc() mapstructure.DecodeHookFuncValue { | ||
return func(from reflect.Value, to reflect.Value) (interface{}, error) { | ||
if from.Kind() == reflect.Slice && from.IsNil() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets start with this:
nil != initialized and len 0
foo:
foo: []
What is the behavior we want in these cases? Please document them somewhere, in order for me to understand if the implementation is ok.
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
Description:
mapstructure library doesn't override full slice during unmarshalling. Origin issue: mitchellh/mapstructure#74 (comment) To address this we zeroes every slice before unmarshalling unless user provided slice is nil.
Link to tracking Issue: #4001