From bae6be915fc87e27beba27b3625b91db32a73d0d Mon Sep 17 00:00:00 2001 From: Nicholas Tindle Date: Tue, 27 Jan 2026 23:39:56 -0600 Subject: [PATCH] fix(backend): replace graph_exec_id or "" fallbacks with asserts The empty string fallback was dead code since store_media_file() validates graph_exec_id before these lines execute. Replace with explicit asserts for clearer failure if assumptions are ever violated. Co-Authored-By: Claude Opus 4.5 --- .../backend/backend/blocks/google/gmail.py | 13 ++++++------- .../backend/backend/blocks/spreadsheet.py | 3 ++- autogpt_platform/backend/backend/blocks/text.py | 5 ++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/autogpt_platform/backend/backend/blocks/google/gmail.py b/autogpt_platform/backend/backend/blocks/google/gmail.py index 8f3d9dd615..2040cabe3f 100644 --- a/autogpt_platform/backend/backend/blocks/google/gmail.py +++ b/autogpt_platform/backend/backend/blocks/google/gmail.py @@ -121,9 +121,8 @@ async def create_mime_message( execution_context=execution_context, return_format="for_local_processing", ) - abs_path = get_exec_file_path( - execution_context.graph_exec_id or "", local_path - ) + assert execution_context.graph_exec_id # Validated by store_media_file + abs_path = get_exec_file_path(execution_context.graph_exec_id, local_path) part = MIMEBase("application", "octet-stream") with open(abs_path, "rb") as f: part.set_payload(f.read()) @@ -1191,7 +1190,8 @@ async def _build_reply_message( execution_context=execution_context, return_format="for_local_processing", ) - abs_path = get_exec_file_path(execution_context.graph_exec_id or "", local_path) + assert execution_context.graph_exec_id # Validated by store_media_file + abs_path = get_exec_file_path(execution_context.graph_exec_id, local_path) part = MIMEBase("application", "octet-stream") with open(abs_path, "rb") as f: part.set_payload(f.read()) @@ -1721,9 +1721,8 @@ To: {original_to} execution_context=execution_context, return_format="for_local_processing", ) - abs_path = get_exec_file_path( - execution_context.graph_exec_id or "", local_path - ) + assert execution_context.graph_exec_id # Validated by store_media_file + abs_path = get_exec_file_path(execution_context.graph_exec_id, local_path) part = MIMEBase("application", "octet-stream") with open(abs_path, "rb") as f: part.set_payload(f.read()) diff --git a/autogpt_platform/backend/backend/blocks/spreadsheet.py b/autogpt_platform/backend/backend/blocks/spreadsheet.py index 6388172561..a13f9e2f6d 100644 --- a/autogpt_platform/backend/backend/blocks/spreadsheet.py +++ b/autogpt_platform/backend/backend/blocks/spreadsheet.py @@ -113,8 +113,9 @@ class ReadSpreadsheetBlock(Block): ) # Get full file path + assert execution_context.graph_exec_id # Validated by store_media_file file_path = get_exec_file_path( - execution_context.graph_exec_id or "", stored_file_path + execution_context.graph_exec_id, stored_file_path ) if not Path(file_path).exists(): raise ValueError(f"File does not exist: {file_path}") diff --git a/autogpt_platform/backend/backend/blocks/text.py b/autogpt_platform/backend/backend/blocks/text.py index fa121a07e7..07807adb16 100644 --- a/autogpt_platform/backend/backend/blocks/text.py +++ b/autogpt_platform/backend/backend/blocks/text.py @@ -455,9 +455,8 @@ class FileReadBlock(Block): ) # Get full file path - file_path = get_exec_file_path( - execution_context.graph_exec_id or "", stored_file_path - ) + assert execution_context.graph_exec_id # Validated by store_media_file + file_path = get_exec_file_path(execution_context.graph_exec_id, stored_file_path) if not Path(file_path).exists(): raise ValueError(f"File does not exist: {file_path}")