thriftpy2 icon indicating copy to clipboard operation
thriftpy2 copied to clipboard

struct required field is not verified

Open shuoli84 opened this issue 4 years ago • 4 comments

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?

shuoli84 avatar Feb 20 '20 15:02 shuoli84

Yes, I think Thriftpy should validate the arguments are all passed, even it breaks the compatibility.

ethe avatar Feb 23 '20 14:02 ethe

@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 avatar May 27 '20 23:05 iamsudip

@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 avatar May 28 '20 02:05 ethe

@ethe Can you have a look at #132

iamsudip avatar May 28 '20 22:05 iamsudip