dify icon indicating copy to clipboard operation
dify copied to clipboard

Invalid variable not giving checklist error

Open AndyMik90 opened this issue 1 year ago • 1 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] Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.8

Cloud or Self Hosted

Cloud, Self Hosted (Docker), Self Hosted (Source)

Steps to reproduce

CleanShot 2024-05-23 at 08 21 30

if a variable in nodes are invalid, it doesn't trigger warnings in the checklist.

✔️ Expected Behavior

Warning on invalid variable

❌ Actual Behavior

Can publish and run workflows/chatflows with invalid variables set.

AndyMik90 avatar May 23 '24 06:05 AndyMik90

The issue you're experiencing with Dify version 0.6.8, where invalid variables in nodes do not trigger warnings in the checklist, is due to several factors in the codebase:

  1. useChecklist Hook:

    • The useChecklist hook does not properly handle invalid variables due to the way the errorMessage is checked and handled. The function returns false immediately, preventing the invalid node from being added to the needWarningNodes list.
  2. checkNodeValid Function:

    • The checkNodeValid function always returns true, meaning it does not perform any actual validation on the node's variables.
  3. getNodeOutputVars Function:

    • This function does not include comprehensive validation for the variables, focusing more on formatting and filtering variables based on their types and structures.

Steps to Address the Issue

  1. Update checkNodeValid Function:

    • Implement proper validation logic to ensure it accurately checks for invalid variables.
    import type { VariableAssignerNodeType } from './types'
    
    export const checkNodeValid = (payload: VariableAssignerNodeType) => {
      const { variables } = payload
      if (!variables or variables.length === 0) {
        return false
      }
      for (const variable of variables) {
        if (!variable or variable.length === 0) {
          return false
        }
      }
      return true
    }
    
  2. Enhance useChecklist Hook:

    • Modify the useChecklist hook to ensure that invalid nodes are added to the needWarningNodes list and that the function does not return prematurely.
    if (errorMessage) {
        notify({ type: 'error', message: `[${node.data.title}] ${errorMessage}` })
        needWarningNodes.push(node)
    }
    
  3. Improve getNodeOutputVars Function:

    • Add comprehensive validation logic to enforce strict validation rules for variables.

By implementing these changes, you should be able to ensure that invalid variables trigger warnings in the checklist, preventing workflows/chatflows from being published and run with these invalid variables.

Details

Sources


About Dosu This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

dosubot[bot] avatar May 23 '24 06:05 dosubot[bot]