python-3.xparameter-passingrobotframeworkkeyword-argumentpositional-parameter

Got multiple Arguements in one function call but not in another function call


I am working on Robot Framework, one of my base method is written in python for building a SQL query with n columns and multiple where conditions. The function looks like,

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('"', '')

I am calling this method in my Robot keywords as:

Get Query With Filter Conditions    ${tableName}    ${column}    &{tableFilter}

This function is called in two other keywords. For one it works fine. for another it keeps throwing error as

Keyword 'queryBuilderUtility.Get Query With Filter Conditions' got multiple values for argument 'table_name'.

The Keyword that works fine looks as:

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}

The functions That always throws error looks like:

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}

Can someone help me to get rectified what is the mistake I am doing here?


Solution

  • The issue is due to key value pair in the dictionary. One of the key in the dictionary

    &{tableFilter}=    Create Dictionary
        Set To Dictionary    ${tableFilter}    table_name=GENERAL
    

    is same as that of one of the argument in the

    def get_query_with_filter_conditions(table_name, *column, **where):
    

    Changed the argument in get_query_with_filter_conditions function from table_name to p_table_name and it worked. As the function takes positional arguments which can be specified as named parameter, python got confused with the table_name parameter I have passed with that of the key table_name in the dictionary.