Skip to content

Commit

Permalink
enforce required arguments, fixes #72
Browse files Browse the repository at this point in the history
  • Loading branch information
iamsudip committed Aug 31, 2019
1 parent f4aa812 commit 1fa360e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions thriftpy2/thrift.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,22 @@ def __getattr__(self, _api):
def __dir__(self):
return self._service.thrift_services

def _validate_required_args(self, _api, api_args):
thrift_spec = getattr(self._service, _api + "_args").thrift_spec
for item in thrift_spec.items():
arg = item[1][1]
required = item[1][2]
if required and arg not in api_args:
raise TApplicationException(
TApplicationException.UNKNOWN_METHOD,
'{arg} is required argument for {service}.{api}'.format(
arg=arg, service=self._service, api=_api))

def _req(self, _api, *args, **kwargs):
_kw = args2kwargs(getattr(self._service, _api + "_args").thrift_spec,
*args)
kwargs.update(_kw)
self._validate_required_args(_api, kwargs)
result_cls = getattr(self._service, _api + "_result")

self._send(_api, **kwargs)
Expand Down

0 comments on commit 1fa360e

Please sign in to comment.