feat(workflow): Mustache lambda helpers for missing-key defaults (fn.*)#5684
Merged
shahargl merged 2 commits intokeephq:mainfrom Mar 11, 2026
Merged
feat(workflow): Mustache lambda helpers for missing-key defaults (fn.*)#5684shahargl merged 2 commits intokeephq:mainfrom
shahargl merged 2 commits intokeephq:mainfrom
Conversation
|
@nflx is attempting to deploy a commit to the KeepHQ Team on Vercel. A member of the Team first needs to authorize it. |
Member
Contributor
2854bbf to
862f50d
Compare
Contributor
|
Target branch is not in the allowed branches list. |
Contributor
Author
|
PR ready, (if accepted). |
…efaults
Inject a set of named lambda helpers into every Chevron render context so
workflow templates can safely reference custom or enriched alert fields that
may be absent without triggering RenderException:
{{#fn.na}}{{ alert.someOptionalField }}{{/fn.na}} → "N/A" if missing
{{#fn.default}}{{ alert.slack_timestamp }}{{/fn.default}} → "" if missing
{{#fn.upper}}{{ alert.severity }}{{/fn.upper}} → uppercased value
Two-part change:
Backend (iohandler.py):
- Add WORKFLOW_HELPERS constant with fn.{default,na,upper,lower,strip} lambdas
- Inject into context on every _render() call
- Disable safe mode automatically when template contains {{#fn.}} sections
(same pattern as existing {{^ inverted-section bypass); the lambda already
returns a safe default so RenderException must not be raised
Frontend (mustache.ts, validate-mustache-yaml.ts, validate-mustache-ui-builder.ts):
- Filter Mustache sigil tokens (#, /, ^, !, >) from extractMustacheVariables()
so the workflow builder does not flag {{#fn.na}} / {{/fn.na}} as invalid
variable references
- Apply the same sigil guard inside validateMustacheVariableForYAMLStep() and
validateMustacheVariableForUIBuilderStep() so the YAML editor's own inline
extraction loop (which bypasses extractMustacheVariables) is also covered
This is Option E of the missing-key handling design; provider-level field
defaulting (Option A) remains correct for known provider schema fields.
Cover the three unchecked items from the PR test plan: - fn.na on a missing alert field → 'N/A' - fn.default on a missing alert field → '' - fn.upper / fn.lower / fn.strip on a present field value
862f50d to
876197d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #5682. Also addresses the root cause of #5070 and is a lighter-weight alternative to the Jinja migration requested in #4594.
Injects a set of named lambda helpers into every Chevron render context so workflow templates can safely reference custom or enriched alert fields that may be absent — without triggering
RenderException:Changes
Backend
keep/iohandler/iohandler.py(+23 lines):WORKFLOW_HELPERSconstant withfn.{default,na,upper,lower,strip}Chevron lambdas_render()call{{#fn.(lambda already returns a safe default, soRenderExceptionmust not be raised)Frontend
keep-ui/entities/workflows/lib/mustache.ts(+3 lines):#,/,^,!,>) fromextractMustacheVariables()so the workflow builder doesn't flag{{#fn.na}}/{{/fn.na}}as invalid variable referencesDesign rationale
See #5682 for the full two-category analysis. The short version:
panelUrl,instance) → defaulted in_format_alert(), no workflow-layer handling neededslack_timestampfromenrich_alert, optional labels) → no provider can default these;fn.*helpers give workflow authors a clean per-field default syntaxThis does not change behaviour for any existing workflow that does not use
{{#fn.sections.Test plan
fn.naon missing key →"N/A"fn.defaulton missing key →""fn.upper/fn.lower/fn.stripon present value{{#fn.na}}{{ alert.x }}{{/fn.na}}— no "invalid variable" warningRenderException