Skip to content

Commit

Permalink
THRIFT-5352: Fix construction of Py exceptions with no fields
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
spladug authored and fishy committed Feb 22, 2021
1 parent 2c0f932 commit cee3ddb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/py/src/Thrift.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions test/DebugProtoTest.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ exception MutableException {
1: string msg;
} (python.immutable = "false")

exception ExceptionWithoutFields {}

service ServiceForExceptionWithAMap {
void methodThatThrowsAnException() throws (1: ExceptionWithAMap xwamap);
}
Expand Down
5 changes: 4 additions & 1 deletion test/py/TestFrozen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -104,6 +104,9 @@ def test_frozen_exception(self):
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"))
Expand Down

0 comments on commit cee3ddb

Please sign in to comment.