diff --git a/changelog.d/+use-copy-for-statedump.fixed.md b/changelog.d/+use-copy-for-statedump.fixed.md new file mode 100644 index 00000000..470dedb4 --- /dev/null +++ b/changelog.d/+use-copy-for-statedump.fixed.md @@ -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 diff --git a/src/zino/state.py b/src/zino/state.py index 29cd4d8f..bc877a4b 100644 --- a/src/zino/state.py +++ b/src/zino/state.py @@ -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() 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()