This is an automated email from the ASF dual-hosted git repository. yuxuan pushed a commit to branch 0.14.0 in repository https://gitbox.apache.org/repos/asf/thrift.git
commit cee3ddb0e0a18d0aa1a1f5b06e643604c5c4ee86 Author: Neil Williams <[email protected]> AuthorDate: Tue Feb 16 15:12:15 2021 -0800 THRIFT-5352: Fix construction of Py exceptions with no fields Client: py When no fields are present, we don't get the special constructor that uses __setattr__ to avoid these checks. So the default constructor sets message normally and triggers the anti-mutation tripwires. --- lib/py/src/Thrift.py | 2 +- test/DebugProtoTest.thrift | 2 ++ test/py/TestFrozen.py | 5 ++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/py/src/Thrift.py b/lib/py/src/Thrift.py index ef655ea..81fe8cf 100644 --- a/lib/py/src/Thrift.py +++ b/lib/py/src/Thrift.py @@ -90,7 +90,7 @@ class TException(Exception): def __init__(self, message=None): Exception.__init__(self, message) - self.message = message + super(TException, self).__setattr__("message", message) class TApplicationException(TException): diff --git a/test/DebugProtoTest.thrift b/test/DebugProtoTest.thrift index 1ab0f6a..5d0face 100644 --- a/test/DebugProtoTest.thrift +++ b/test/DebugProtoTest.thrift @@ -245,6 +245,8 @@ exception MutableException { 1: string msg; } (python.immutable = "false") +exception ExceptionWithoutFields {} + service ServiceForExceptionWithAMap { void methodThatThrowsAnException() throws (1: ExceptionWithAMap xwamap); } diff --git a/test/py/TestFrozen.py b/test/py/TestFrozen.py index ce7425f..f859398 100755 --- a/test/py/TestFrozen.py +++ b/test/py/TestFrozen.py @@ -21,7 +21,7 @@ from DebugProtoTest import Srv from DebugProtoTest.ttypes import CompactProtoTestStruct, Empty, Wrapper -from DebugProtoTest.ttypes import ExceptionWithAMap, MutableException +from DebugProtoTest.ttypes import ExceptionWithAMap, MutableException, ExceptionWithoutFields from thrift.Thrift import TFrozenDict from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol, TCompactProtocol @@ -104,6 +104,9 @@ class TestFrozenBase(unittest.TestCase): mutexc.msg = 'bar' self.assertEqual(mutexc.msg, 'bar') + def test_frozen_exception_with_no_fields(self): + ExceptionWithoutFields() + def test_frozen_exception_serialization(self): result = Srv.declaredExceptionMethod_result( xwamap=ExceptionWithAMap(blah="error"))
