venmo / business-rules

Python DSL for setting up business intelligence rules that can be configured without code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: argument after ** must be a mapping, not list

movihus opened this issue · comments

Hello, I am trying to implement this package and I have a error I can't understand

I have defined my variables like this

from business_rules.variables import *

class CommissionVariables(BaseVariables):

    def __init__(self, commission):
        self.commission = commission

    @numeric_rule_variable
    def month(self):
        return self.commission.mes

    @numeric_rule_variable
    def commission_amount(self):
        return self.commission.mto_comi_pdv

My actions like this

from business_rules.fields import *
from business_rules.actions import *

class CommissionActions(BaseActions):
    def __init__(self, commission):
        self.commission = commission

    @rule_action(params={ "paid": FIELD_TEXT, "obs": FIELD_TEXT })
    def mark_recharge_payment(self, paid, obs):
        self.commission.pagado_recarga = paid
        self.commission.observacion_recarga = obs
        self.commission.save()

    @rule_action(params={ "paid": FIELD_TEXT, 'obs': FIELD_TEXT })
    def mark_first_charge_payment(self, paid, obs):
        self.commission.pagado_primera_carga = paid
        self.commission.observacion_primera_carga = obs
        self.commission.save()

And my rules like this

rules = [
    { 
        "conditions": { "all": [ 
            { 
                "name": "month",
                "operator": "greater_than",
                "value": 4,
            },
            { 
                "name": "commission_amount",
                "operator": "greater_than",
                "value": 0,
            },
        ]},
        "actions": [
            { 
                "name": "mark_recharge_payment",
                "params": [{ "name": "paid", "value": 'NO' }, { 'name': 'obs', 'value': 'Not paid' }],
            },
        ],
    }
]

And when I try to run de rules:

commissions = Commission.query.limit(10).all()

for commission in commissions:
    run_all(rule_list=rules,
            defined_variables=CommissionVariables(commission),
            defined_actions=CommissionActions(commission),
            stop_on_first_trigger=True
           )

I got this error

Traceback (most recent call last):
  File "/home/<user>/commissions/main.py", line 51, in <module>
    stop_on_first_trigger=True
  File "build/bdist.linux-x86_64/egg/business_rules/engine.py", line 10, in run_all
  File "build/bdist.linux-x86_64/egg/business_rules/engine.py", line 21, in run
  File "build/bdist.linux-x86_64/egg/business_rules/engine.py", line 96, in do_actions
  TypeError: mark_recharge_payment() argument after ** must be a mapping, not list

Could you tell me what I did wrong?.

Thanks

Ok, I think i found the error, I followed your example of your README that says that the params of the rule must be like this:

"params":[{"name":"number_to_order", "value": 40}]}

But it's wrong, the params must be declared like this:

"params":{"number_to_order": 40}

You must update your README

Greetings

Thank you for bringing this to my attention, #27 makes the README consistent with the expected format.

gaand fatike bhadwe