Skip to content

Commit 92c930a

Browse files
committed
Restore _write and _flush in WriteLogger.__setstate__
After unpickling a WriteLogger, calling any log method (msg, info, debug, etc.) raises AttributeError because __setstate__ only restores _file and _lock but not _write and _flush. BytesLogger.__setstate__ already handles this correctly, and so does WriteLogger.__deepcopy__ — this was just an oversight in __setstate__.
1 parent a223a65 commit 92c930a

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/structlog/_output.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ def __setstate__(self, state: Any) -> None:
186186
else:
187187
self._file = stderr
188188

189+
self._write = self._file.write
190+
self._flush = self._file.flush
189191
self._lock = _get_lock_for_file(self._file)
190192

191193
def __deepcopy__(self, memodict: dict[str, object]) -> WriteLogger:

0 commit comments

Comments
 (0)