[Python-checkins] [3.7] bpo-35726: Prevented QueueHandler formatting from affecting other handlers (GH-11537) (GH-12716)

Ned Deily webhook-mailer at python.org
Thu May 2 13:02:48 EDT 2019


https://github.com/python/cpython/commit/386b6f07a9703746590a5f29281b93c931c0e6d3
commit: 386b6f07a9703746590a5f29281b93c931c0e6d3
branch: 3.7
author: Xtreak <tir.karthi at gmail.com>
committer: Ned Deily <nad at python.org>
date: 2019-05-02T13:02:42-04:00
summary:

[3.7] bpo-35726: Prevented QueueHandler formatting from affecting other handlers (GH-11537) (GH-12716)

QueueHandler.prepare() now makes a copy of the record before modifying and enqueueing it, to avoid affecting other handlers in the chain.
(cherry picked from commit da6424e96ada72c15c91bddb0a411acf7119e10a)

Co-authored-by: Manjusaka <lizheao940510 at gmail.com>

files:
A Misc/NEWS.d/next/Library/2019-01-13-01-33-00.bpo-35726.dasdas.rst
M Lib/logging/handlers.py

diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index e213e438c31a..3727bf0677cd 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -27,6 +27,7 @@
 from stat import ST_DEV, ST_INO, ST_MTIME
 import queue
 import threading
+import copy
 
 #
 # Some constants...
@@ -1377,6 +1378,8 @@ def prepare(self, record):
         # exc_info and exc_text attributes, as they are no longer
         # needed and, if not None, will typically not be pickleable.
         msg = self.format(record)
+        # bpo-35726: make copy of record to avoid affecting other handlers in the chain.
+        record = copy.copy(record)
         record.message = msg
         record.msg = msg
         record.args = None
diff --git a/Misc/NEWS.d/next/Library/2019-01-13-01-33-00.bpo-35726.dasdas.rst b/Misc/NEWS.d/next/Library/2019-01-13-01-33-00.bpo-35726.dasdas.rst
new file mode 100644
index 000000000000..f47cdc128e85
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-01-13-01-33-00.bpo-35726.dasdas.rst
@@ -0,0 +1 @@
+QueueHandler.prepare() now makes a copy of the record before modifying and enqueueing it, to avoid affecting other handlers in the chain.



More information about the Python-checkins mailing list