refactor(workflow): add Jinja2 renderer abstraction for template transform#3
Conversation
…de and threaded it through DifyNodeFactory so TemplateTransform nodes receive the dependency by default, keeping behavior unchanged unless an override is provided. Changes are in `api/core/workflow/nodes/template_transform/template_transform_node.py` and `api/core/workflow/nodes/node_factory.py`. **Commits** - chore(workflow): identify TemplateTransform dependency on CodeExecutor - feat(workflow): add CodeExecutor constructor injection to TemplateTransformNode (defaulting to current behavior) - feat(workflow): inject CodeExecutor from DifyNodeFactory when creating TemplateTransform nodes **Tests** - Not run (not requested) Next step: run `make lint` and `make type-check` if you want to validate the backend checks.
…Transform to use it, keeping CodeExecutor as the default adapter while preserving current behavior. Updates are in `api/core/workflow/nodes/template_transform/template_renderer.py`, `api/core/workflow/nodes/template_transform/template_transform_node.py`, `api/core/workflow/nodes/node_factory.py`, and `api/tests/unit_tests/core/workflow/nodes/template_transform/template_transform_node_spec.py`. Commit-style summary: - feat(template-transform): add Jinja2 template renderer abstraction with CodeExecutor adapter - refactor(template-transform): use renderer in node/factory and update unit test patches Tests not run (not requested).
…ode creation to return TemplateTransformNode directly for template-transform nodes in `api/core/workflow/nodes/node_factory.py`. Commit-style summary: - refactor(template-transform): derive TemplateRenderError from ValueError - refactor(node-factory): instantiate TemplateTransformNode directly with injected renderer Tests not run (not requested).
…ts/core/workflow/nodes/template_transform/template_transform_node_spec.py`) chore(type-check): ran `make type-check` (basedpyright clean, 0 errors) No errors reported.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
🤖 Augment PR SummarySummary: Refactors Template Transform rendering by introducing a Jinja2 renderer abstraction, making template execution easier to inject and mock. Changes:
Technical Notes: Execution still flows through 🤖 Was this summary useful? React with 👍 or 👎 |
| result = self._code_executor.execute_workflow_code_template( | ||
| language=CodeLanguage.JINJA2, code=template, inputs=variables | ||
| ) | ||
| except CodeExecutionError as exc: |
There was a problem hiding this comment.
execute_workflow_code_template() can raise non-CodeExecutionError exceptions (e.g., ValueError from transform_response), which currently won’t be wrapped and may bubble up and crash node execution. Consider normalizing those failures into TemplateRenderError so TemplateTransformNode can consistently return FAILED instead of throwing.
🤖 Was this useful? React with 👍 or 👎
| rendered = result.get("result") | ||
| if rendered is not None and not isinstance(rendered, str): | ||
| raise TemplateRenderError("Template render result must be a string.") | ||
| return rendered |
There was a problem hiding this comment.
render_template() is typed to return str, but this returns None when result["result"] is missing/None, which will later break len(rendered) in TemplateTransformNode._run. Consider raising TemplateRenderError when the render result is missing/None to keep the contract consistent.
🤖 Was this useful? React with 👍 or 👎
Benchmark PR from agentic-review-benchmarks#3