Browse Source

Update msg_stack.py (#1820)

* Update msg_stack.py

1、[msg.to_dict() for msg in msgs], msg is not instanse of Message, it not has a func of to_dict(), so msg.to_dict() will accur JSONDecodeError;
2、json.dump(new_data, file), it appends new_data to the end of the file instead of overwriting from the beginning, Hence, it's necessary to first perform file.seek(0) and file.truncate().

* Update opendevin/server/session/msg_stack.py

---------

Co-authored-by: Yufan Song <33971064+yufansong@users.noreply.github.com>
yangpryili 1 year ago
parent
commit
52e21c20e3
1 changed files with 5 additions and 1 deletions
  1. 5 1
      opendevin/server/session/msg_stack.py

+ 5 - 1
opendevin/server/session/msg_stack.py

@@ -99,7 +99,11 @@ class MessageStack:
                 new_data = {}
                 for sid, msgs in data.items():
                     if sid != del_sid:
-                        new_data[sid] = [msg.to_dict() for msg in msgs]
+                        new_data[sid] = msgs
+                # Move the file pointer to the beginning of the file to overwrite the original contents
+                file.seek(0)
+                # clean previous content
+                file.truncate()
                 json.dump(new_data, file)
         except FileNotFoundError:
             pass