dify icon indicating copy to clipboard operation
dify copied to clipboard

"Invalid value selector" occurred when pass textarea input params to code execute node

Open all4you opened this issue 1 year ago • 3 comments

Self Checks

  • [X] This is only for bug report, if you would like to ask a question, please head to Discussions.
  • [X] I have searched for existing issues search for existing issues, including closed ones.
  • [X] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [X] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • [X] Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.11

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

I create a workflow,and make several input params, some of them are textarea: image image

I find when the textarea params contains line break, the code execute node get error: image

image

image

after i remove systemMessage param,everything goes ok image

✔️ Expected Behavior

code execute node run successfully

❌ Actual Behavior

code execute node occurred error:Invalid value selector

all4you avatar Jun 27 '24 08:06 all4you

Hello @all4you! I'm here to assist you with any bugs, questions, or contributions you may have. Let's work together to resolve the issue you're experiencing.

The "Invalid value selector" error in the convert_body node is likely caused by a mismatch between the expected and actual structure of the input parameters. Specifically, this error can occur if the query_variable_selector does not match the expected format or if the variable referenced in the selector is not found in the provided input parameters.

Here are some potential causes and solutions:

  1. Variable Selector Mismatch: Ensure that the variable_selector in your node configuration correctly matches the input parameters. For example, if your systemMessage parameter is expected to be used in the convert_body node, make sure it is correctly referenced.

  2. Multiline Text Handling: The convert_body node should handle multiline text inputs properly. Ensure that the input parameters are correctly formatted and that any special characters, such as line breaks, are properly encoded.

  3. Validation and Parsing: The convert_body node uses various methods to validate and parse input parameters. Ensure that the input parameters conform to the expected types and structures. For example, the _check_string method ensures that the value is a string and replaces any null characters (\x00).

Here is a relevant snippet from the test case that demonstrates how the variable_selector is used:

def test_execute_if_else_result_true():
    node = IfElseNode(
        tenant_id='1',
        app_id='1',
        workflow_id='1',
        user_id='1',
        user_from=UserFrom.ACCOUNT,
        invoke_from=InvokeFrom.DEBUGGER,
        config={
            'id': 'if-else',
            'data': {
                'title': '123',
                'type': 'if-else',
                'logical_operator': 'and',
                'conditions': [
                    {
                        'comparison_operator': 'contains',
                        'variable_selector': ['start', 'array_contains'],
                        'value': 'ab'
                    },
                    # other conditions...
                ]
            }
        }
    )
    # construct variable pool
    pool = VariablePool(system_variables={
        SystemVariable.FILES: [],
        SystemVariable.USER_ID: 'aaa'
    }, user_inputs={})
    pool.append_variable(node_id='start', variable_key_list=['array_contains'], value=['ab', 'def'])
    # other variable appends...

    # Mock db.session.close()
    db.session.close = MagicMock()

    # execute node
    result = node._run(pool)

    assert result.status == WorkflowNodeExecutionStatus.SUCCEEDED
    assert result.outputs['result'] is True

In this test, if the variable_selector ['start', 'array_contains'] does not match any variable in the input parameters, it could lead to an "Invalid value selector" error [1].

Additionally, the _convert_to_knowledge_retrieval_node method in the WorkflowConverter class sets the query_variable_selector based on the app mode and retrieve configuration. If the retrieve_config.query_variable is not provided or does not match the expected format, it can also result in an "Invalid value selector" error [2].

Ensure that your input parameters and their selectors are correctly configured to avoid this error.

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Jun 27 '24 08:06 dosubot[bot]

I found a very wired thing, when I naming the textarea input params start with 'sysXX' like : systemMessage,sysMessage, it cause the bug, when I change the name to prompt , it is ok. image when I change it to systemPrompt: image the 'start' node is missing, and then the bug occurred image

all4you avatar Jun 27 '24 10:06 all4you

Test on v0.6.12-fix1

  1. message in Code execution node and end node work fine image

  2. sys_messgae in Code execution node work fail image

  3. sysmessge in Code execution node work fail image

  4. systemMessage in Code execution node work fail image

  5. message in code execution work fine, systemMessage in end node, work fail image

Sakura4036 avatar Jul 04 '24 07:07 Sakura4036