From 70a3f67e0327fd2cb2d94617331b3a164bbbda34 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 7 Mar 2024 06:00:05 -1000 Subject: [PATCH] Avoid extracting the stack twice in system_log (#112572) --- homeassistant/components/system_log/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/system_log/__init__.py b/homeassistant/components/system_log/__init__.py index 3ede14a2ad6..8b158041cdc 100644 --- a/homeassistant/components/system_log/__init__.py +++ b/homeassistant/components/system_log/__init__.py @@ -180,8 +180,8 @@ class LogEntry: self.exception = "".join(traceback.format_exception(*record.exc_info)) _, _, tb = record.exc_info # Last line of traceback contains the root cause of the exception - if traceback.extract_tb(tb): - self.root_cause = str(traceback.extract_tb(tb)[-1]) + if extracted := traceback.extract_tb(tb): + self.root_cause = str(extracted[-1]) self.source = source self.count = 1 self.key = (self.name, source, self.root_cause)