venmo/business-rules

Setting default evaluation value for a rule variable

vikasverma93 opened this issue · 1 comments

Right now we define rules like this. for this variable_1 should be there is in class variables or else at the time of evaluation it throws an error.

"rules": {
    	"conditions": { 
    		"all": [
    			{
    				"name": "variable_1",
    				"operator": "is_true",
    				"value": true
    			}
    		]
    	},
        "actions": [
    		{
    			"name": "action_1",
    			"params": {
    			}
    		}
    	]
}

My requirement is that is variable_1 is not there in class variables, either it should be ignored for evaluation or I should be able to pass a default value at the time of rules generation.

"rules": {
    	"conditions": { 
    		"all": [
    			{
    				"name": "variable_1",
    				"operator": "is_true",
    				"value": true,
                                "default": true
    			}
    		]
    	},
        "actions": [
    		{
    			"name": "action_1",
    			"params": {
    			}
    		}
    	]
}

Can some help me with this, how can I achieve this.

Thanks in advance

Without changes in the engine logic via a PR that is possibly merged into the code base, you could possibly deal with the AssertionError. An alternative would be to change your variable class definition to dynamically introduce a method with the default value using __getattr__ .

This package assumes that a possible dashboard would only show the declared variables on the frontend via the exported ruleset JSON. I am wondering what business/product problem you are trying to solve. How is it possible to receive an undefined variable? There may be other alternatives.