-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: Jinja2 template engine in workflow templates #4595
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
feat: Jinja2 template engine in workflow templates #4595
Conversation
@EnotShow is attempting to deploy a commit to the KeepHQ Team on Vercel. A member of the Team first needs to authorize it. |
@EnotShow lot of unit tests are failing, can you fix that? :) |
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.
tests failing
Also a quick question about backwards compatibility - not sure if I understand if this will still support mustache or we're replacing to Jinja completely? Maybe we should support |
|
β¦mplates Signed-off-by: Ihor <88674695+EnotShow@users.noreply.github.com>
@talboren This is ready for review, but I ran into an issue with Jinja2. Jinja2 doesn't allow hyphens in identifier names when accessed as attributes in templates. To work around this, I implemented a function which replaces code like:
with:
This change uses dictionary-style access, which is valid in Jinja2 for keys that contain hyphens. It seems to work, but I not sure if this solution is proper enough. What you think? |
makes absolute sense! I'll try to review it ASAP. |
β¦mplates Signed-off-by: Ihor <88674695+EnotShow@users.noreply.github.com>
β¦mplates Signed-off-by: Ihor <88674695+EnotShow@users.noreply.github.com>
β¦mplates Signed-off-by: Ihor Korolenko <88674695+korolenkowork@users.noreply.github.com>
π¨ BugBot couldn't runPull requests from forked repositories are not yet supported (requestId: serverGenReqId_06c76e83-cbf9-46fb-b4f7-80acc0b782b5). |
@korolenkowork see comment on the other PR. This is crazy great but I need to see how I prioritize reviewing it. |
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.
Bug: Mustache Template Validation Incorrectly Disables Safe Rendering
The MustacheIOHandler._validate_template
method unconditionally sets safe=False
and logs a debug message about inverted sections. This changes the intended behavior, as the original logic only disabled safe rendering when inverted sections ({{^
or {{ ^
) were actually present in the template. Consequently, safe rendering is now always disabled for Mustache templates.
keep/iohandler/iohandler.py#L695-L702
keep/keep/iohandler/iohandler.py
Lines 695 to 702 in 58f0d0a
def _validate_template(self, template, safe): | |
self.logger.debug( | |
"Safe render is not supported when there are inverted sections." | |
) | |
safe = False | |
return super()._validate_template(template, safe) |
Bug: IO Handler Initialization Typo
The attribute self.io_nandler
is a typo and should be self.io_handler
. This typo occurs when initializing the IO handler within the Workflow
class, leading to the correct self.io_handler
attribute never being set. Consequently, any attempt to access self.io_handler
later in the workflow will result in an AttributeError
.
keep/workflowmanager/workflow.py#L64-L76
keep/keep/workflowmanager/workflow.py
Lines 64 to 76 in 58f0d0a
self.context_manager.set_consts_context(workflow_consts) | |
self.context_manager.set_secret_context() | |
self.logger = logging.getLogger(__name__) | |
self.workflow_debug = workflow_debug | |
self.workflow_permissions = workflow_permissions | |
match workflow_templating: | |
case TemplateEngine.MUSTACHE: | |
self.io_nandler = MustacheIOHandler(context_manager) | |
case TemplateEngine.JINJA2: | |
self.io_nandler = Jinja2IOHandler(context_manager) | |
case _: | |
self.io_nandler = MustacheIOHandler(context_manager) |
Was this report helpful? Give feedback by reacting with π or π
Hey, @shahargl does it means that changes permanently declined? |
Closes #4594
π Description
This PR added the whole power of Jinja2 templating to the KeepHQ workflow
β Checks
β¨ Features
π Improvements
During Jinja2 rendering, only missing top-level keys can be detected β full key paths cannot be tracked.
Example: {{ alert.namespase }} will report {{ namespace }} as missing, but due to how Jinja2's Undefined class works, it cannot identify the full path to the missing value.
Itβs not possible to use a tracking dictionary for Jinja2 in the same way as Mustache, because Jinja2 internally converts the context to a plain dict during rendering.