webargs @use_kargs 验证不起作用

问题描述

自从升级python版本和webargs包后,服务器的验证都在下降。他们应该得到的参数是空的。在没有验证的情况下运行是完美的。

webargs升级是从版本 5 到 6.1。 我确实检查了升级到 6.1 的文档,但我尝试的所有更改(例如添加“location='query'”)由于某种原因都不起作用。

我有这个主要查询

app.route('/api/v1/corr/gene/<gene_id>',methods=['GET'])
@use_kwargs(genes_args,validate=[gene_must_be_unambiguous])
def query_by_gene(gene_id):
    print('in the function')

    from api.v1.service import generate_graph_by_gene
    edges,nodes,params = generate_graph_by_gene(gene_id)
genes_args = {
    'gene_id': fields.Str(location='view_args',required=True)
}
def gene_must_be_unambiguous(args):
    models = 'api.v1.models'
    print(args)

    from importlib import import_module
    names = getattr(import_module(models),'ChaperoneFamilyCompartments')
    db = getattr(import_module(models),'ChaperoneCorrelationsV8')

    gene = args['gene_id']

    potential_genes = names.check_name(gene)
    if len(potential_genes) > 1:
        raise ValidationError(
            'Ambiguous gene identifier {} matches the following: {}'.format(gene,potential_genes))
    elif len(potential_genes) < 1:
        raise ValidationError(
            'No entry matches {} {} in our database.'.format(gene,potential_genes))
    else:
        node_filter = or_(db.Protein1.in_([gene]),db.Protein2.in_([gene]))
        q = db.query.filter(node_filter).all()
        if q is None:
            raise ValidationError(
                'No entry matches {} {} in our database.'.format(gene,potential_genes))

        # Inject ENSG name to be passed instead of whatever the user filled in.
        args['gene_id'] = potential_genes[0]

在 'gene_must_be_unambigous' 中,gene_id 始终为空。

这是我尝试进行更改之前的代码

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...