You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Execution of gomplate --missing-key zero -f missingkey.tmpl with 4.1.0 generates the following output:
$c: [map[keywords:32 lang:C] map[keywords:25 lang:Go] map[keywords:357 lang:COBOL]]
$d: [map[keywords:32 lang:C] map[keywords:25 lang:Go] map[keywords:357 lang:COBOL]]
Render $c:
C has 32 keywords.
[] does not exist.
good
good
good
Go has 25 keywords.
[] does not exist.
good
good
good
COBOL has 357 keywords.
[] does not exist.
good
good
good
Render $d:
C has 32 keywords.
[<no value>] does not exist.
good
bad
bad
Go has 25 keywords.
[<no value>] does not exist.
good
bad
bad
COBOL has 357 keywords.
[<no value>] does not exist.
good
bad
bad
I thought I'd commented on this already, but - in some ways the behaviour is expected:
For $c (the []map[string]string from data.CSVByRow), the operation results in a failed lookup from the map[string]string, and since the type of value is string, the zero value that's returned is an empty string "".
$d however is populated by coll.Slice and coll.Dict. coll.Dict produces a map[string]interface{}, and since the zero value of interface{} is nil, that's what's returned.
In Go templates, nil is rendered as <no value>.
If you choose the other missing-key behaviour (--missing-key invalid), rather than the zero values both simply get nil (and are rendered as <no value>).
I'm really not sure if there's anything reasonable that can be done here - given the different types, I believe this is working as well as can be expected.
One workaround could be to use the default function:
[{{.missingKey | default ""}}] does not exist.
This'll work with both missing-key=zero and missing-key=invalid (but not with the default error behaviour.
I'm going to close this issue as I don't think there's anything that can be done. If you have ideas, feel free to re-open and we can discuss!
With
missingkey.tmpl
:Execution of
gomplate --missing-key zero -f missingkey.tmpl
with 4.1.0 generates the following output:See also discussion #2215.
The text was updated successfully, but these errors were encountered: