thriftpy
thriftpy copied to clipboard
Missing validate method
Structs that get defined seem to be missing the validate method that is added by thrift during the gen process. Considering that I am planning to use my structs in multiple contexts I use the validate method when using the objects outside of the RPC context.
https://github.com/apache/thrift/blob/01a77ab01e7459d96059a2b49d9885d14a360ef1/compiler/cpp/src/generate/t_py_generator.cc#L908
The validate method is a simple is not None
, and as far as I remember it's not enforced in protocol layer, you have to manually call it if you concern about it.
In our use case, we never see a requirement for this method, and we almost always prefer optional
to required
. Sometimes the required
can cause some troubles when using thrift across multiple versions and languages.
So I will recommend to do it with is not None
or local implemented function, the codes needed should be trivial.
The validate method that gets constructed for every thrift struct is that required fields are not None
which is true. However the classes generated by thriftpy do not have that method which means that if you choose to use that feature of the thrift compiled code and want to use it interoperable with thriftpy you will introduce errors(which is how I noticed it). I want the freedom to switch back and forth between thriftpy and thrift but that isn't possible when the base class structure for struct objects is incomplete.
I never said that the code needed for it should be non trivial I just haven't found where in the library to add that(mainly due to time constraints)
Hi, we have considered about this feature, but we finally gave it up due to some historical reasons. We are using apache thrift that time, and most of our thrift files can't pass this validation.
Ping @maralla : How about providing an option parameter to enable this validation?