Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add decorator behind the describe decorator ,query_parameters args do not working #52

Open
zengzhengrong opened this issue Mar 9, 2020 · 1 comment

Comments

@zengzhengrong
Copy link

zengzhengrong commented Mar 9, 2020

example

@describe(paths="/api/v1/kubernetes/nodes/percent", methods="GET",query_parameters=['is_worker'])
@token_identify_permission('kubernetes_rest_api_server',['admin','user'])
def get_nodes_avg_percent(request,is_worker:bool=True):

I add the token_identify_permission behind ,when i start server it pop error

Traceback (most recent call last):
  File "rest_api.py", line 94, in <module>
    add_route(app,get_nodes_avg_percent)
  File "/usr/local/lib/python3.6/site-packages/sanic_transmute/route.py", line 15, in add_route
    get_swagger_spec(app_or_blueprint).add_func(transmute_func, context)
  File "/usr/local/lib/python3.6/site-packages/transmute_core/swagger/__init__.py", line 55, in add_func
    swagger_path = transmute_func.get_swagger_path(transmute_context)
  File "/usr/local/lib/python3.6/site-packages/transmute_core/function/transmute_function.py", line 78, in get_swagger_path
    operation = self.get_swagger_operation(context)
  File "/usr/local/lib/python3.6/site-packages/transmute_core/function/transmute_function.py", line 94, in get_swagger_operation
    parameters = get_swagger_parameters(self.parameters, context)
  File "/usr/local/lib/python3.6/site-packages/transmute_core/http_parameters/swagger.py", line 15, in get_swagger_parameters
    "required": arginfo.default is NoDefault,
AttributeError: 'NoneType' object has no attribute 'default'

I check

dict_items([('is_worker', Param(argument_name='is_worker', description=None, arginfo=None))])

arginfo should be a Argument(name='is_worker', default=True, type=<class 'bool'> , but it set None , and i remove args query_parameters=['is_worker'] or remove custom decorator ,it work fine

I just use sanic-transmute==0.1.3

@toumorokoshi
Copy link
Owner

toumorokoshi commented Jul 7, 2020

Hi! This is probably happening because the decorator extracts attributes from your decorated function, rather than the raw one that lies below.

What does your decorator looks like? It messes with the argument detection if your outer function, for example, does something like *arg, **kwarg which has no real signature.

If you use something like functools.wraps, maybe we could add a patch that will look at deeper functions for obviously annotated function wrappers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants