Skip to content

Commit 8caf706

Browse files
fix(robot-server): Fix migrations failing when commands contain certain text (#17682)
1 parent 37b4dcb commit 8caf706

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

robot-server/robot_server/persistence/_migrations/v6_to_v7.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,17 @@ def _migrate_command_table_with_new_command_intent_col(
7575
for row in dest_transaction.execute(select_commands).all():
7676
data = json.loads(row.command)
7777
new_command_intent = (
78-
# Account for old_row.command["intent"] being NULL.
78+
# Account for the `intent` prop of the old command JSON being omitted or `null`.
79+
# We convert either case to the SQL string "protocol".
7980
"protocol"
80-
if "intent" not in row.command or data["intent"] == None # noqa: E711
81+
if "intent" not in data or data["intent"] is None
8182
else data["intent"]
8283
)
8384

8485
dest_transaction.execute(
85-
f"UPDATE run_command SET command_intent='{new_command_intent}' WHERE row_id={row.row_id}"
86+
sqlalchemy.update(schema_7.run_command_table)
87+
.where(schema_7.run_command_table.c.row_id == row.row_id)
88+
.values(command_intent=new_command_intent),
8689
)
8790

8891

robot-server/robot_server/persistence/_migrations/v7_to_v8.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ def _migrate_command_table_with_new_command_error_col_and_command_status(
8181
for row in dest_transaction.execute(select_commands).all():
8282
data = json.loads(row.command)
8383
new_command_error = (
84-
# Account for old_row.command["error"] being null.
84+
# Account for the `error` prop of the old command JSON being omitted or `null`.
85+
# We convert either case to SQL `null`.
8586
None
86-
if "error" not in row.command or data["error"] is None
87+
if "error" not in data or data["error"] is None
8788
else json.dumps(data["error"])
8889
)
8990
# parse json as enum

0 commit comments

Comments
 (0)