refactor(csv-import): Enhance nutrition data processing and template rendering
Deploy Development / deploy (push) Successful in 48s
Build Test / pytest-backend (push) Successful in 3s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 16s

- Updated the nutrition import logic to utilize a new row processing specification, improving data aggregation and validation.
- Refactored the template rendering process in the workflow executor to use Jinja2's Environment with ChainableUndefined for better handling of missing attributes.
- Added backward-compatible shortcuts for accessing decision signals in node contexts, enhancing flexibility in template usage.
- Introduced import row processing options in CSV templates, allowing for more customizable data handling during imports.
This commit is contained in:
Lars committed 2026-04-10 11:56:43 +02:00
1 parent 8b67f7ab55
commit c0fcdea1fe
9 files changed
+357 -22

No files matched your search

+10 -2
View File
@@ -15,7 +15,7 @@ from datetime import datetime
import uuid
import logging
import json
from jinja2 import Template, TemplateError
from jinja2 import Environment, ChainableUndefined, TemplateError
from workflow_models import (
WorkflowGraph, NodeExecutionState, ExecutionResult,
@@ -618,6 +618,11 @@ def execute_end_node(
"reasoning_anchors": node_state.reasoning_anchors or "",
"status": node_state.status.value if node_state.status else "unknown",
}
# Backward-compatible shortcut:
# allow {{node_id.relevanz}} in addition to {{node_id.decision_signals.relevanz}}
if node_state.decision_signals:
for signal_key, signal_value in node_state.decision_signals.items():
node_context[signal_key] = signal_value
# Add normalized signals as {{node_id.signal_ID}}
# NOTE: question_type now IS the ID (not the type!)
@@ -660,7 +665,10 @@ def execute_end_node(
# Render template
try:
jinja_template = Template(node.template)
# ChainableUndefined keeps missing nested attributes renderable
# so Jinja's default filter can handle them.
jinja_env = Environment(undefined=ChainableUndefined)
jinja_template = jinja_env.from_string(node.template)
final_output = jinja_template.render(template_context)
logger.info(f"End node {node.id}: Template rendered successfully ({len(final_output)} chars)")
except TemplateError as te: