-
Notifications
You must be signed in to change notification settings - Fork 40
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
return nil instead of empty map #13
Conversation
|
@@ -87,7 +87,7 @@ func (d Directives) Int(key string) (int, bool) { | |||
func (d Directives) Object(key string) Directives { | |||
v, ok := d[key] | |||
if !ok { | |||
return make(Directives) | |||
return nil | |||
} | |||
m, ok := v.(map[string]interface{}) | |||
if !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.
The following line should also be nil
, right?
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 it exists but theres nothing in the map, then we should likely keep it? I pushed this already but can make changes if we need
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 other question is does anything outside of env vars use this today?
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.
This if !ok
on the type assertion would mean that e.g. environment_variable = 10
- that it's not a table. IMO it should be treated the same as if it weren't set.
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.
yeah that maybe we would want to error and say that its set to an incorrect type even, should i add a card for this? I dont think weve really touched the logic of directives too much. Were unblocked for now but youre right we may want to add more to this
keyType, pResult := p.determinePersistType(f, annot) | ||
if pResult == nil { | ||
if annot.Capability.Directives.Object(core.EnvironmentVariableDirective) != nil { |
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 annot.Capability.Directives.Object(core.EnvironmentVariableDirective) != nil { | |
if len(annot.Capability.Directives.Object(core.EnvironmentVariableDirective)) == 0 { |
This will work for both nil and 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.
it doesnt let you do len on that object
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.
Ah, yeah you'd have to len(map[string]interface{}(..))
maybe worth adding a method to Directive
at some point (receivers can be nil).
• Does any part of it require special attention?
• Does it relate to or fix any issue?
fixes the bug
Standard checks