From a8046ffe2d47b044b0e043de8623adbc2f5ba560 Mon Sep 17 00:00:00 2001 From: Ed Catmur Date: Tue, 28 Jun 2022 15:50:28 +0100 Subject: [PATCH] don't set nested exception if already set --- include/pybind11/pytypes.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index f5ba91206..9205e2b38 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -581,7 +581,8 @@ public: error_already_set() : m_fetched_error{new detail::error_fetch_and_normalize("pybind11::error_already_set"), m_fetched_error_deleter} { - static_cast(*this) = m_fetched_error->get_cause_as_nested(); + if (not nested_ptr()) + static_cast(*this) = m_fetched_error->get_cause_as_nested(); } /// The what() result is built lazily on demand.