Skip to content

Commit

Permalink
Use copy of state for state dumps to file
Browse files Browse the repository at this point in the history
  • Loading branch information
johannaengland committed Aug 30, 2024
1 parent e2164d5 commit 73e016c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/+use-copy-for-statedump.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use a copy of the Zino state for saving it to a file to avoid errors due to changes to the state in the middle of saving
3 changes: 2 additions & 1 deletion src/zino/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ class ZinoState(BaseModel):
def dump_state_to_file(self, filename: str):
"""Dumps the full state to a file in JSON format"""
_log.debug("dumping state to %s", filename)
copied_state = self.model_copy(deep=True)
with open(filename, "w") as statefile:
statefile.write(self.model_dump_json(exclude_none=True, indent=2))
statefile.write(copied_state.model_dump_json(exclude_none=True, indent=2))

@classmethod
@log_time_spent()
Expand Down

0 comments on commit 73e016c

Please sign in to comment.