Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Report]: Operators.In and Operators.NotIn with not working properly when trying to match the rule setting the condition value as null #130

Closed
1 task done
isabelneto opened this issue Mar 10, 2023 · 0 comments · Fixed by #149
Assignees
Labels
bug Something isn't working

Comments

@isabelneto
Copy link
Contributor

isabelneto commented Mar 10, 2023

Prerequisites

  • I have searched issues to ensure it has not already been reported

Description

When creating a rule using the Operators.In or Operators.NotIn we are getting one exception when trying to match the rule with that condition set to null (or, nonexistent, in the case where the condition type is string, since it's default is null).
The problem seems to be in Rules.Framework, when trying to cast.

Steps to reproduce

  1. Create a rule like the following:
this.Add(
    this.Add(
        RuleBuilder
            .NewRule<RuleContentType, ConditionType>()
            .WithName("Some Rule")
            .WithContent(
                RuleContentType.SomeContentType,
                  "SomeText"
            )
            .WithCondition(x => x
                .AsValued(ConditionType.SomeConditionType).OfDataType<string>()
                .WithComparisonOperator(Operators.In)
                .SetOperand(new[] { "11111", "22222", "33333", "44444", "55555" })
                .Build()
            )
            .WithDateBegin(DateTime.Parse("2022-01-01"))
            .Build(),
        RuleAddPriorityOption.ByPriorityNumber(1)
    );
  1. Create a test case where SomeConditionType is null

Expected behavior

It shouldn't match the rule but no errors should occour.

Actual behavior

It is throwing an exception:
System.ArgumentException: Parameter value or contained value is not convertible to String. (Parameter 'leftOperand')

System.ArgumentException
Parameter value or contained value is not convertible to String. (Parameter 'leftOperand')
   at Rules.Framework.Evaluation.ValueEvaluation.Dispatchers.ConditionEvalDispatcherBase.ConvertToDataType(Object operand, String paramName, DataTypeConfiguration dataTypeConfiguration)
   at Rules.Framework.Evaluation.ValueEvaluation.Dispatchers.OneToManyConditionEvalDispatcher.EvalDispatch(DataTypes dataType, Object leftOperand, Operators operator, Object rightOperand)
   at Rules.Framework.Evaluation.ValueEvaluation.DeferredEval.Eval[TConditionType](IDictionary`2 conditions, IValueConditionNode`1 valueConditionNode, Object rightOperand, MatchModes matchMode)
   at Rules.Framework.Evaluation.ValueEvaluation.DeferredEval.Eval[TConditionType](IDictionary`2 conditions, ValueConditionNode`1 valueConditionNode, MatchModes matchMode)
   at Rules.Framework.Evaluation.ValueEvaluation.DeferredEval.<>c__DisplayClass3_0`1.<GetDeferredEvalFor>b__4(IDictionary`2 conditions)
   at Rules.Framework.Evaluation.Specification.FuncSpecification`1.IsSatisfiedBy(T input)
   at Rules.Framework.Evaluation.ConditionsEvalEngine`1.Eval(IConditionNode`1 conditionNode, IDictionary`2 conditions, EvaluationOptions evaluationOptions)
   at Rules.Framework.RulesEngine`2.<>c__DisplayClass18_0.<MatchAsync>b__2(Rule`2 r)
   at System.Linq.Enumerable.WhereEnumerableIterator`1.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Rules.Framework.RulesEngine`2.MatchAsync(TContentType contentType, DateTime matchDateBegin, DateTime matchDateEnd, IEnumerable`1 conditions, EvaluationOptions evaluationOptions)
   at Rules.Framework.RulesEngine`2.MatchOneAsync(TContentType contentType, DateTime matchDateTime, IEnumerable`1 conditions)
   at Farfetch.Finance.OrderTransactions.Data.RulesEngine.Tests.Engine.ContentTypeBaseTests.MatchOneAsync(DateTime expectedMatchDate, Condition`1[] expectedConditions) in C:\ave\_git\order-transactions-service\src\Data.RulesEngine.Tests\Engine\ContentTypeBaseTests.cs:line 44
   at Farfetch.Finance.OrderTransactions.Data.RulesEngine.Tests.Rules.RulesTestHelper.TestRuleAsync[TRuleContent](String ruleName, DateTime expectedMatchDate, Nullable`1 expectedEndDate, Condition`1[] expectedConditions, TRuleContent expectedValue) in C:\ave\_git\order-transactions-service\src\Data.RulesEngine.Tests\Rules\RulesTestHelper.cs:line 25
   at Farfetch.Finance.OrderTransactions.Data.RulesEngine.Tests.Rules.Transactions.PromoCodeX10NetRulesTests.GetRulesSpecifications_PromoCodeX10Net_WithConditionsRule(String ruleName, DateTime expectedMatchDate, Condition`1[] expectedConditions, RuleResultContent expectedValue) in C:\ave\_git\order-transactions-service\src\Data.RulesEngine.Tests\Rules\Transactions\PromoCodeX10NetRulesTests.cs:line 343
   at Xunit.Sdk.TestInvoker`1.<>c__DisplayClass48_1.<<InvokeTestMethodAsync>b__1>d.MoveNext() in C:\Dev\xunit\xunit\src\xunit.execution\Sdk\Frameworks\Runners\TestInvoker.cs:line 264
--- End of stack trace from previous location ---
   at Xunit.Sdk.ExecutionTimer.AggregateAsync(Func`1 asyncAction) in C:\Dev\xunit\xunit\src\xunit.execution\Sdk\Frameworks\ExecutionTimer.cs:line 48
   at Xunit.Sdk.ExceptionAggregator.RunAsync(Func`1 code) in C:\Dev\xunit\xunit\src\xunit.core\Sdk\ExceptionAggregator.cs:line 90

System.InvalidCastException
Object must implement IConvertible.
   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
   at Rules.Framework.Evaluation.ValueEvaluation.Dispatchers.ConditionEvalDispatcherBase.ConvertToDataType(Object operand, String paramName, DataTypeConfiguration dataTypeConfiguration)

Rules Framework version

v1.7.7

@isabelneto isabelneto added the bug Something isn't working label Mar 10, 2023
@isabelneto isabelneto changed the title [Bug Report]: Operators.In and Operators.NotIn with an array of strings not working properly [Bug Report]: Operators.In and Operators.NotIn with not working properly when trying to match the rule setting the condition value as null Mar 13, 2023
@luispfgarces luispfgarces moved this from Future to Current in Rules framework roadmap Apr 3, 2023
@luispfgarces luispfgarces moved this from Current to Done in Rules framework roadmap Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
1 participant