conductor-oss / conductor

Conductor is an event driven orchestration platform
https://conductor-oss.org
Apache License 2.0
16.01k stars 421 forks source link

Validation errors in tasks with SWITCH type containing JS expressions after upgrading to 3.16.0 #101

Closed SchepiLove closed 6 months ago

SchepiLove commented 6 months ago

Describe the bug When loading workflow definition with SWITCH type tasks with JS expressions, I get validation error. Also, when loading workflow definition in task there are no inputParameters, which can lead to erroneous execution of eval() Object returnValue = ScriptEvaluator.eval(expression, inputParameters);

Details Conductor version: 3.16.0 Persistence implementation: Redis Queue implementation: Dynoqueues Lock: Redis Task definition: SWITCH

To Reproduce Сreate a workflow definition with a SWITCH type task with an expression:

function check(){
    var inputResult = $.inputResult;
    var result = "OK";
    if (!inputResult || !inputResult.serviceResult || inputResult.serviceResult.resultType === "ERROR") {
        result = "ERROR";
    }
    if (inputResult.serviceResult.resultCode === "-1001") {
        result = "NOT_FOUND";
}
    return result;
}

check()

Get the logs: ConstraintViolationImpl{interpolatedMessage='Expression is not well formatted: TypeError: Cannot read property "resultCode" from undefined in at line number 10, taskType: SWITCH taskName SWITCH_TASK', propertyPath=tasks[12], rootBeanClass=class com.netflix.conductor.common.metadata.workflow.WorkflowDef, messageTemplate='Expression is not well formatted: TypeError: Cannot read property "resultCode" from undefined in at line number 10, taskType: SWITCH taskName SWITCH_TASK'}

Expected behavior Before the upgrade, these tasks with expressions worked properly and eval() returned the expected result

Additional context changes in validation with version upgrade: https://github.com/Netflix/conductor/pull/3805

SchepiLove commented 6 months ago

Everything was solved by passing to the input only those fields that were required in this expression. But filtering still had to be moved to jsonPath, because validation did not pass on the expression "expression": "Java.from($.statuses).filter(function (el) { return el.toLowerCase() !== 'ok' }).length > 0"