From 92c930ab9e2aff10c9c1d69bec1481977d0ad6a6 Mon Sep 17 00:00:00 2001 From: Kadir Can Ozden <101993364+bysiber@users.noreply.github.com> Date: Fri, 20 Feb 2026 14:19:51 +0300 Subject: [PATCH] Restore _write and _flush in WriteLogger.__setstate__ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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__. --- src/structlog/_output.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/structlog/_output.py b/src/structlog/_output.py index b1612de6..a35df747 100644 --- a/src/structlog/_output.py +++ b/src/structlog/_output.py @@ -186,6 +186,8 @@ def __setstate__(self, state: Any) -> None: else: self._file = stderr + self._write = self._file.write + self._flush = self._file.flush self._lock = _get_lock_for_file(self._file) def __deepcopy__(self, memodict: dict[str, object]) -> WriteLogger: