From cb182daaafd7506f1426c5753aa3d36cdad796cd Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Tue, 4 Feb 2025 19:51:28 +0000 Subject: [PATCH] [Common] Fix Twisted 24.x no longer calling addCallbacks in Deferred subclass A change to Deferred logic in 24.10 means that `addCallbacks` is no longer being called in Deferred methods. This is a problem since our subclass of Deferred for coroutines was using that mechanism to check awaited status. Fixed by extending each method that requires awaited status check. Reference: https://github.com/twisted/twisted/pull/12283 Reference: https://github.com/twisted/twisted/commit/4d04b64b77f0c25dbb0f514e2c59c70a44b32c09 --- deluge/decorators.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/deluge/decorators.py b/deluge/decorators.py index 7b1896c13..04e1796bf 100644 --- a/deluge/decorators.py +++ b/deluge/decorators.py @@ -196,11 +196,27 @@ class CoroutineDeferred(defer.Deferred): d = defer.ensureDeferred(self.coro) d.chainDeferred(self) - def addCallbacks(self, *args, **kwargs): # noqa: N802 + def _callback_activate(self): + """Verify awaited status before calling activate.""" assert not self.awaited, 'Cannot add callbacks to an already awaited coroutine.' self.activate() + + def addCallback(self, *args, **kwargs): # noqa: N802 + self._callback_activate() + return super().addCallback(*args, **kwargs) + + def addCallbacks(self, *args, **kwargs): # noqa: N802 + self._callback_activate() return super().addCallbacks(*args, **kwargs) + def addErrback(self, *args, **kwargs): # noqa: N802 + self._callback_activate() + return super().addErrback(*args, **kwargs) + + def addBoth(self, *args, **kwargs): # noqa: N802 + self._callback_activate() + return super().addBoth(*args, **kwargs) + _RetT = TypeVar('_RetT')