@@ -427,8 +427,12 @@ def _save_data(self, data: Data, path: Path, fmt: str) -> str:
427427 )
428428
429429 if is_text_empty and is_data_empty :
430- print (f"[SaveFile] ⚠️ SKIP: Data content is empty, skipping write. data.data={ repr (data .data )} , text={ repr (text_content )} " , flush = True )
430+ print (
431+ f"[SaveFile] ⚠️ SKIP: Data content is empty, skipping write. data.data={ repr (data .data )} , text={ repr (text_content )} " ,
432+ flush = True ,
433+ )
431434 logger .info (f"[SaveFile] Skipping write to '{ path } ' - content is empty" )
435+ setattr (self , "_skipped_last_write" , True )
432436 return f"Skipped writing empty content to '{ path } '"
433437
434438 file_exists = path .exists ()
@@ -609,8 +613,12 @@ async def _save_message(self, message: Message, path: Path, fmt: str) -> str:
609613 # This prevents writing empty files which indicates a problem in the workflow
610614 print (f"[SaveFile] 💾 Final content: type={ type (content ).__name__ } , length={ len (content ) if isinstance (content , str ) else 'N/A' } , value={ repr (content )[:200 ]} " , flush = True )
611615 if not content or (isinstance (content , str ) and content .strip () == "" ):
612- print (f"[SaveFile] ⚠️ SKIP: Content is empty, skipping write. message.text={ repr (message .text )} , content={ repr (content )} " , flush = True )
616+ print (
617+ f"[SaveFile] ⚠️ SKIP: Content is empty, skipping write. message.text={ repr (message .text )} , content={ repr (content )} " ,
618+ flush = True ,
619+ )
613620 logger .info (f"[SaveFile] Skipping write to '{ path } ' - content is empty" )
621+ setattr (self , "_skipped_last_write" , True )
614622 return f"Skipped writing empty content to '{ path } '"
615623
616624 if fmt == "txt" :
@@ -788,6 +796,9 @@ async def _save_to_local(self) -> Message:
788796 print (f"[SaveFile] 📁 Target file path: { file_path } " , flush = True )
789797 print (f"[SaveFile] 📁 File exists: { file_path .exists ()} " , flush = True )
790798
799+ # Track whether we skipped writing due to empty content
800+ setattr (self , "_skipped_last_write" , False )
801+
791802 # Save the input to file based on type
792803 if input_type == "DataFrame" :
793804 confirmation = self ._save_dataframe (self .input , file_path , file_format )
@@ -801,8 +812,11 @@ async def _save_to_local(self) -> Message:
801812
802813 print (f"[SaveFile] ✅ Save result: { confirmation } " , flush = True )
803814
804- # Upload the saved file
805- await self ._upload_file (file_path )
815+ # Upload the saved file only if we actually wrote content
816+ if not getattr (self , "_skipped_last_write" , False ):
817+ await self ._upload_file (file_path )
818+ else :
819+ print ("[SaveFile] ⏭️ Upload skipped because no content was written." , flush = True )
806820
807821 # Return the final file path and confirmation message
808822 final_path = Path .cwd () / file_path if not file_path .is_absolute () else file_path
0 commit comments