thriftpy2
thriftpy2 copied to clipboard
struct required field is not verified
Similar as #72 , required field in struct should be enforced before send out. Current implementation only validate method args.
Since the init func is generated on the fly, so maybe we should add some validation code in init?
"""Generate `__init__` function based on TPayload.default_spec
For example::
spec = [('name', 'Alice'), ('number', None)]
will generate a types.FunctionType object representing::
def __init__(self, name='Alice', number=None):
self.name = name
self.number = number
if number is None: raise ValueError()
This way actually breaks init then assign behavior. Or add a validate method on each generated class and call it just before send?
Yes, I think Thriftpy should validate the arguments are all passed, even it breaks the compatibility.
@ethe I have some free time these days. Since I worked on enforcing required args
issue, I guess somewhat I have some idea. Can you point me how to implement this?
@iamsudip Thank you, I think we can modify the function thrift.py:init_func_generator
, and change all required field from keyword arguments to normal arguments, and please make sure that the argument sequence is matched with thrift IDL.
@ethe Can you have a look at #132