From 682f2bc4246fc192eaad1bed76177d4b7e00a2f8 Mon Sep 17 00:00:00 2001 From: Jocelyn Giroux Date: Tue, 3 Dec 2024 07:42:26 -0500 Subject: [PATCH] Restore missing key default behavior We must restore the default mode to avoid error on further template evaluation --- template/extra_runtime.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/template/extra_runtime.go b/template/extra_runtime.go index e98e817..06ce20b 100644 --- a/template/extra_runtime.go +++ b/template/extra_runtime.go @@ -499,14 +499,16 @@ func optimizedRunTemplate(t *Template, withClone bool, source string, args ...in // Ignore missing keys internalTemplate.Option("missingkey=default") } else { - // Return error on missing keys in order to retry + // Return error on missing keys in order to retry but with context cloning + // and ensure that we restore the original behavior on error handling + defer func() { internalTemplate.Option("missingkey=default") }() internalTemplate.Option("missingkey=error") } // We execute the resulting template if err = internalTemplate.Execute(&out, context); err != nil { if !withClone { - TemplateLog.Debug("Running template with context cloning because:", err) + InternalLog.Debug("Running template with context cloning because:", err) t.context = parentContext return optimizedRunTemplate(t, true, source, args...) }