首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在一个函数调用中得到多个论证,而在另一个函数调用中没有得到多个论证。

在一个函数调用中得到多个论证,而在另一个函数调用中没有得到多个论证。
EN

Stack Overflow用户
提问于 2020-09-22 11:58:17
回答 1查看 103关注 0票数 0

我正在开发机器人框架,我的基本方法之一是用python编写的,用于构建一个包含n列和多个where条件的SQL查询。这个函数看起来像,

代码语言:javascript
复制
from pypika import Query, Table, Field
def get_query_with_filter_conditions(table_name, *column, **where):
    table_name_with_no_lock = table_name + ' with (nolock)'
    table = Table(table_name_with_no_lock)
    where_condition = get_where_condition(**where)
    sql_query = Query.from_(table).select(
        *column
    ).where(
        Field(where_condition)
    )
    return str(sql_query).replace('"', '')

在我的机器人关键字中,我将此方法称为:

代码语言:javascript
复制
Get Query With Filter Conditions    ${tableName}    ${column}    &{tableFilter}

这个函数在另外两个关键字中调用。首先,它工作得很好。另一方面,它一直抛出错误,如

关键字“带有筛选条件的queryBuilderUtility.Get查询”获得了参数“table_name”的多个值.

工作良好的关键字看起来如下:

代码语言:javascript
复制
Verify the ${element} in ${grid} is fetched from ${column} column in ${tableName} table from DB
    [Documentation]    Verifies Monetary values in the View Sale Grid
    ${feature}=    Get Variable Value    ${FEATURE_NAME}
    ${filterValue}=    Get Variable value    ${FILTER_VALUE}
    ${queryFilter}=    Get the Test Data    valid    ${filterValue}    ${feature}
    &{tableFilter}=    Create Dictionary
    Set To Dictionary    ${tableFilter}    ${filterValue}=${queryFilter}
    Set To Dictionary    ${tableFilter}    form_of_payment_type=${element}
    ${tableName}=    Catenate    SEPARATOR=.    SmartPRASales    ${tableName}
    ${query}=    Get query with Filter Conditions    ${tableName}    ${column}    &{tableFilter}
    Log    ${query}
    @{queryResult}=    CommonPage.Get a Column values from DB    ${query}

总是抛出错误的函数如下所示:

代码语言:javascript
复制
Verify ${element} drop down contains all values from ${column} column in ${tableName} table
    [Documentation]    To verify the drop down has all values from DB
    ${feature}=    Get Variable Value    ${FEATURE_NAME}
    ${filterElement}=    Run Keyword If    '${element}'=='batch_type'    Set Variable    transaction_type
    ...    ELSE IF    '${element}'=='channel'    Set Variable    agency_type
    ...    ELSE    Set Variable    ${element}
    &{tableFilter}=    Create Dictionary
    Set To Dictionary    ${tableFilter}    table_name=GENERAL
    Set To Dictionary    ${tableFilter}    column_name=${filterElement}
    Set To Dictionary    ${tableFilter}    client_id=QR
    Log    ${tableFilter}
    Log    ${tableName}
    Log    ${column}
    ${tableName}=    Catenate    SEPARATOR=.    SmartPRAMaster    ${tableName}
    ${query}=    Get Query With Filter Conditions    ${tableName}    ${column}    &{tableFilter}
    Log    ${query}
    @{expectedvalues}=    CommonPage.Get a Column values from DB    ${query}

有人能帮我纠正一下吗?我在这里犯的错误是什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-23 02:53:58

这个问题是由于字典中的键值对造成的。字典中的关键之一

代码语言:javascript
复制
&{tableFilter}=    Create Dictionary
    Set To Dictionary    ${tableFilter}    table_name=GENERAL

中的参数之一相同。

代码语言:javascript
复制
def get_query_with_filter_conditions(table_name, *column, **where):

将get_query_with_filter_conditions函数中的参数从table_name更改为p_table_name,并且工作正常。由于函数采用可以指定为命名参数的位置参数,所以python与我传递的table_name参数和字典中键table_name的参数混淆了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64009279

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档