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>
This commit is contained in:
yangpryili 2024-05-16 18:04:05 +08:00 committed by GitHub
parent 15685f9aba
commit 52e21c20e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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