nested state path
This commit is contained in:
@@ -23,15 +23,23 @@ def apply_builtin_merge(
|
||||
|
||||
if strategy == "append":
|
||||
if current_value is None:
|
||||
return [incoming_value] if not isinstance(incoming_value, list) else incoming_value
|
||||
return (
|
||||
[incoming_value]
|
||||
if not isinstance(incoming_value, list)
|
||||
else incoming_value
|
||||
)
|
||||
if not isinstance(current_value, list):
|
||||
raise WorkflowExecutionError(
|
||||
f"cannot append into non-list state path {destination_path!r}"
|
||||
)
|
||||
return [
|
||||
*current_value,
|
||||
*incoming_value,
|
||||
] if isinstance(incoming_value, list) else [*current_value, incoming_value]
|
||||
return (
|
||||
[
|
||||
*current_value,
|
||||
*incoming_value,
|
||||
]
|
||||
if isinstance(incoming_value, list)
|
||||
else [*current_value, incoming_value]
|
||||
)
|
||||
|
||||
if strategy == "merge_object":
|
||||
if current_value is None:
|
||||
|
||||
@@ -39,7 +39,9 @@ def apply_mapped_state(
|
||||
missing_field_message: str,
|
||||
) -> dict[str, Any]:
|
||||
if has_overlapping_paths(mapping.values()):
|
||||
raise WorkflowExecutionError("mapped state patch has overlapping destination paths")
|
||||
raise WorkflowExecutionError(
|
||||
"mapped state patch has overlapping destination paths"
|
||||
)
|
||||
|
||||
patch: dict[str, Any] = {}
|
||||
for source_field, destination_path in mapping.items():
|
||||
@@ -69,8 +71,8 @@ def write_state_value(
|
||||
f"executor only supports writes into state.*, got {destination_path!r}"
|
||||
)
|
||||
|
||||
field_name = parts[0]
|
||||
declared_field = workflow.state_schema.fields.get(field_name)
|
||||
declared_path = ".".join(parts)
|
||||
declared_field = workflow.state_schema.fields.get(declared_path)
|
||||
merge_strategy = declared_field.merge_strategy if declared_field else "replace"
|
||||
key_path = parts
|
||||
current_value = get_nested_value(state, key_path)
|
||||
|
||||
Reference in New Issue
Block a user