Skip to content
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

fix(rnd): Fix broken list input pin execution ordering & unlinked dynamic pins on save #8108

Merged
merged 3 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion autogpt_platform/backend/backend/blocks/time_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self):
{"trigger": "Hello", "format": "{time}"},
],
test_output=[
("time", time.strftime("%H:%M:%S")),
("time", lambda _: time.strftime("%H:%M:%S")),
],
)

Expand Down
12 changes: 6 additions & 6 deletions autogpt_platform/backend/backend/data/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,19 +396,19 @@ def merge_execution_input(data: BlockInput) -> BlockInput:

# Merge all input with <input_name>_$_<index> into a single list.
items = list(data.items())
list_input: list[Any] = []

for key, value in items:
if LIST_SPLIT not in key:
continue
name, index = key.split(LIST_SPLIT)
if not index.isdigit():
list_input.append((name, value, 0))
else:
list_input.append((name, value, int(index)))
raise ValueError(f"Invalid key: {key}, #{index} index must be an integer.")

for name, value, _ in sorted(list_input, key=lambda x: x[2]):
data[name] = data.get(name, [])
data[name].append(value)
if int(index) >= len(data[name]):
# Pad list with empty string on missing indices.
data[name].extend([""] * (int(index) - len(data[name]) + 1))
data[name][int(index)] = value

# Merge all input with <input_name>_#_<index> into a single dict.
for key, value in items:
Expand Down
17 changes: 9 additions & 8 deletions autogpt_platform/frontend/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,22 @@ export function setNestedProperty(obj: any, path: string, value: any) {

export function removeEmptyStringsAndNulls(obj: any): any {
if (Array.isArray(obj)) {
// If obj is an array, recursively remove empty strings and nulls from its elements
return obj
.map((item) => removeEmptyStringsAndNulls(item))
.filter(
(item) =>
item !== null && (typeof item !== "string" || item.trim() !== ""),
);
// If obj is an array, recursively check each element,
// but element removal is avoided to prevent index changes.
return obj.map((item) =>
item === undefined || item === null
? ""
: removeEmptyStringsAndNulls(item),
);
majdyz marked this conversation as resolved.
Show resolved Hide resolved
} else if (typeof obj === "object" && obj !== null) {
// If obj is an object, recursively remove empty strings and nulls from its properties
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
const value = obj[key];
if (
value === null ||
(typeof value === "string" && value.trim() === "")
value === undefined ||
majdyz marked this conversation as resolved.
Show resolved Hide resolved
(typeof value === "string" && value === "")
) {
delete obj[key];
} else {
Expand Down
Loading