summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Williams <neil@reddit.com>2021-02-16 15:12:15 -0800
committerYuxuan 'fishy' Wang <fishywang@gmail.com>2021-02-22 10:02:58 -0800
commitcee3ddb0e0a18d0aa1a1f5b06e643604c5c4ee86 (patch)
tree91c2707280b3f147e1fac76e497d0d23e524bb94
parent2c0f932301231c8d9996dc21c183c586e0a80d08 (diff)
downloadthrift-cee3ddb0e0a18d0aa1a1f5b06e643604c5c4ee86.tar.gz
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.
-rw-r--r--lib/py/src/Thrift.py2
-rw-r--r--test/DebugProtoTest.thrift2
-rwxr-xr-xtest/py/TestFrozen.py5
3 files changed, 7 insertions, 2 deletions
diff --git a/lib/py/src/Thrift.py b/lib/py/src/Thrift.py
index ef655ea55..81fe8cf33 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 1ab0f6aea..5d0face4b 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 ce7425f88..f859398dc 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"))