You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by yu...@apache.org on 2021/02/17 00:31:15 UTC
[thrift] branch master updated: THRIFT-5352: Fix construction of Py
exceptions with no fields
This is an automated email from the ASF dual-hosted git repository.
yuxuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git
The following commit(s) were added to refs/heads/master by this push:
new 055fe67 THRIFT-5352: Fix construction of Py exceptions with no fields
055fe67 is described below
commit 055fe67ec1856d25f7ad3b98b5cd172fdf8e2c70
Author: Neil Williams <ne...@reddit.com>
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"))