Problem with rule validation - valid on save, invalid on load

255 Views Asked by At

While testing the unchanged CodeEffects asp.net core demo application (Editor 5.0.4.8, Engine 5.0.2.6) I've found an interesting problem.

If I create an execution rule that checks for example if FirstName contains two spaces, I can save this rule without a problem, and in SaveRule action it passes the validation using editor.Rule.IsValid. Here is an example of the rule definition:

        <if>
            <clause>
                <condition type="contains" stringComparison="OrdinalIgnoreCase">
                    <property name="FirstName" />
                    <value>  </value>
                </condition>
            </clause>
            <then>
                <method name="Register">
                    <value>aaaa</value>
                </method>
            </then>
        </if>

But when refreshing the editor and trying to load this saved rule it won't load into editor. The reason is that the LoadRule controller action returns empty json.

While investigating this further it looks that the editor.GetClientRuleData returns null because the rule is invalid. If I check editor.Rule.IsValid just before calling editor.GetClientRuleData I can see it return false and the editor.Rule.InvalidElements holds one element:

{{c:"",h:"v120"}}

The error message would be "The only allowed operators for empty string values are IS and IS NOT" but of course it's not shown in the editor in the demo project as this is not expected to happen.

Not sure if this is in any way related to the problem, but one obvious difference between LoadRule and SaveRule actions is how the rule is loaded.

When saving the rule, the rule data (coming from the UI) is loaded into editor with

editor.LoadClientData(data.Data);

and when loading the rule it's loaded using the xml (from the storage) effectively calling this:

editor.Rule = Rule.Models.RuleModel.Create(ruleXml, typeof(Models.Patient))

So my question is why can invalid rule pass the validation on save, and then the same rule fails the validation on load? Any fix I can try or a workaround?

1

There are 1 best solutions below

2
On

This issue has been fixed in the latest version of Rule Editor. You need to update Code Effects references from NuGet:

CodeEffects.Rule.Common - 5.0.2.4, CodeEffects.Rule.Editor.Core - 5.0.4.1 (this is the assembly that contains that fix), CodeEffects.Rule.Editor.Web.Core - 5.0.4.8