Template variable interpolation issue (#4332)
This commit is contained in:
@@ -3967,32 +3967,39 @@ class HttpRequestBlock(Block):
|
|||||||
"""Format template parameters in the block fields"""
|
"""Format template parameters in the block fields"""
|
||||||
template_kwargs = {"force_include_secrets": True}
|
template_kwargs = {"force_include_secrets": True}
|
||||||
|
|
||||||
|
def _render_templates_in_json(value: object) -> object:
|
||||||
|
"""
|
||||||
|
Recursively render Jinja templates in nested JSON-like structures.
|
||||||
|
|
||||||
|
This is required because HTTP request bodies are often deeply nested
|
||||||
|
dict/list structures, and templates may appear at any depth.
|
||||||
|
"""
|
||||||
|
if isinstance(value, str):
|
||||||
|
return self.format_block_parameter_template_from_workflow_run_context(
|
||||||
|
value, workflow_run_context, **template_kwargs
|
||||||
|
)
|
||||||
|
if isinstance(value, list):
|
||||||
|
return [_render_templates_in_json(item) for item in value]
|
||||||
|
if isinstance(value, dict):
|
||||||
|
return {
|
||||||
|
cast(str, _render_templates_in_json(key)): _render_templates_in_json(val)
|
||||||
|
for key, val in value.items()
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
|
||||||
if self.url:
|
if self.url:
|
||||||
self.url = self.format_block_parameter_template_from_workflow_run_context(
|
self.url = self.format_block_parameter_template_from_workflow_run_context(
|
||||||
self.url, workflow_run_context, **template_kwargs
|
self.url, workflow_run_context, **template_kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.body:
|
if self.body:
|
||||||
# If body is provided as a template string, try to parse it as JSON
|
self.body = cast(dict[str, Any], _render_templates_in_json(self.body))
|
||||||
for key, value in self.body.items():
|
|
||||||
if isinstance(value, str):
|
|
||||||
self.body[key] = self.format_block_parameter_template_from_workflow_run_context(
|
|
||||||
value, workflow_run_context, **template_kwargs
|
|
||||||
)
|
|
||||||
|
|
||||||
if self.files:
|
if self.files:
|
||||||
# Format file paths in files dictionary
|
self.files = cast(dict[str, str], _render_templates_in_json(self.files))
|
||||||
for field_name, file_path in self.files.items():
|
|
||||||
if isinstance(file_path, str):
|
|
||||||
self.files[field_name] = self.format_block_parameter_template_from_workflow_run_context(
|
|
||||||
file_path, workflow_run_context, **template_kwargs
|
|
||||||
)
|
|
||||||
|
|
||||||
if self.headers:
|
if self.headers:
|
||||||
for key, value in self.headers.items():
|
self.headers = cast(dict[str, str], _render_templates_in_json(self.headers))
|
||||||
self.headers[key] = self.format_block_parameter_template_from_workflow_run_context(
|
|
||||||
value, workflow_run_context, **template_kwargs
|
|
||||||
)
|
|
||||||
|
|
||||||
def validate_url(self, url: str) -> bool:
|
def validate_url(self, url: str) -> bool:
|
||||||
"""Validate if the URL is properly formatted"""
|
"""Validate if the URL is properly formatted"""
|
||||||
|
|||||||
Reference in New Issue
Block a user