From 4814526f91927a257dd941c64c114ef8560120f9 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Mon, 5 Aug 2024 12:38:40 -0400 Subject: [PATCH] Fix regression in CopiedFailure --- src/twisted/newsfragments/12279.bugfix | 1 + src/twisted/python/failure.py | 4 ++++ src/twisted/test/test_failure.py | 11 +++++++++++ 3 files changed, 16 insertions(+) create mode 100644 src/twisted/newsfragments/12279.bugfix diff --git a/src/twisted/newsfragments/12279.bugfix b/src/twisted/newsfragments/12279.bugfix new file mode 100644 index 00000000000..8b6afeabdf2 --- /dev/null +++ b/src/twisted/newsfragments/12279.bugfix @@ -0,0 +1 @@ +Fixed unreleased regression caused by PR 12109. \ No newline at end of file diff --git a/src/twisted/python/failure.py b/src/twisted/python/failure.py index 39712ecf5c7..d253ffad743 100644 --- a/src/twisted/python/failure.py +++ b/src/twisted/python/failure.py @@ -429,6 +429,10 @@ def parents(self): self._parents = [self.type] return self._parents + @parents.setter + def parents(self, parents): + self._parents = parents + def _extrapolate(self, otherFailure): """ Extrapolate from one failure into another, copying its stack frames. diff --git a/src/twisted/test/test_failure.py b/src/twisted/test/test_failure.py index 9a3daae306b..6245dcd0417 100644 --- a/src/twisted/test/test_failure.py +++ b/src/twisted/test/test_failure.py @@ -568,6 +568,17 @@ def test_failurePicklingIncludesParents(self) -> None: f = failure.Failure(ComparableException("hello")) self.assertEqual(f.__getstate__()["parents"], f.parents) + def test_settableParents(self) -> None: + """ + C{Failure.parents} can be set, both before and after pickling. + + This is used by Perspective Broker. + """ + original_failure = failure.Failure(ComparableException("hello")) + original_failure.parents = original_failure.parents[:] + failure2 = pickle.loads(pickle.dumps(original_failure)) + failure2.parents = failure2.parents[:] + class BrokenStr(Exception): """