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

Missing positional argument in wrapper() #11

Closed
lorddaren opened this issue Sep 17, 2014 · 7 comments
Closed

Missing positional argument in wrapper() #11

lorddaren opened this issue Sep 17, 2014 · 7 comments

Comments

@lorddaren
Copy link

I am receiving this error when executing run_all:

Traceback (most recent call last):
  File "ksl.py", line 225, in <module>
    stop_on_first_trigger=False)
  File "/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/business_rules-0.1.3-py3.4.egg/business_rules/engine.py", line 10, in run_all
  File "/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/business_rules-0.1.3-py3.4.egg/business_rules/engine.py", line 19, in run
  File "/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/business_rules-0.1.3-py3.4.egg/business_rules/engine.py", line 31, in check_conditions_recursively
  File "/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/business_rules-0.1.3-py3.4.egg/business_rules/engine.py", line 46, in check_conditions_recursively
  File "/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/business_rules-0.1.3-py3.4.egg/business_rules/engine.py", line 54, in check_condition
  File "/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/business_rules-0.1.3-py3.4.egg/business_rules/engine.py", line 68, in _get_variable_value
TypeError: wrapper() missing 1 required positional argument: 'func'

Variables:

class CarVariables(BaseVariables):
    """ Variables to look for in validating a car """

    def __init__(self, car):
        self.avg_miles_per_year = 20000
        self.car = car

    @numeric_rule_variable
    def mileage(self):
        return self.car.miles

    @numeric_rule_variable
    def price(self):
        return self.car.price

    @numeric_rule_variable
    def year(self):
        return self.car.year

    @string_rule_variable
    def make(self):
        return self.car.make

    @string_rule_variable
    def model(self):
        return self.car.model

    @numeric_rule_variable(label='Mileage over standard yearly miles average.')
    def miles_over_average(self):
        year_diff = datetime.now().year - self.car.year
        avg_miles = self.avg_miles_per_year * year_diff
        avg_diff = self.car.miles - avg_miles
        return avg_diff

Actions:

class CarActions(BaseActions):
    """ Actions that can be taken when rules are met """

    def __init__(self, car):
        logging.getLogger()
        self.car = car

    @rule_action(params={})
    def ready_for_review(self):
        logging.debug('Marking car for review')
        self.car.review = True
        self.car.post = False

    @rule_action(params={})
    def not_for_review(self):
        self.car.review = False
        self.car.post = False

    @rule_action(params={})
    def ready_for_post(self):
        self.car.post = True
@amandaschloss
Copy link

Have you tried using @string_rule_variable() instead of @string_rule_variable? And same for the rest of the variable decorators.

@lorddaren
Copy link
Author

New error:

Traceback (most recent call last):
  File "ksl.py", line 225, in <module>
    stop_on_first_trigger=False)
  File "/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/business_rules-0.1.3-py3.4.egg/business_rules/engine.py", line 10, in run_all
  File "/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/business_rules-0.1.3-py3.4.egg/business_rules/engine.py", line 19, in run
  File "/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/business_rules-0.1.3-py3.4.egg/business_rules/engine.py", line 31, in check_conditions_recursively
  File "/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/business_rules-0.1.3-py3.4.egg/business_rules/engine.py", line 46, in check_conditions_recursively
  File "/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/business_rules-0.1.3-py3.4.egg/business_rules/engine.py", line 54, in check_condition
  File "/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/business_rules-0.1.3-py3.4.egg/business_rules/engine.py", line 68, in _get_variable_value
  File "/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/business_rules-0.1.3-py3.4.egg/business_rules/variables.py", line 67, in memf
TypeError: mileage() missing 1 required positional argument: 'self'

@amandaschloss
Copy link

Hmm. This is after fixing @numeric_rule_variable to @numeric_rule_variable()?

@lorddaren
Copy link
Author

Correct.

@amandaschloss
Copy link

Could you post an example of how you're actually calling engine.run?

@lorddaren
Copy link
Author

Here ya go:

    rules = """[{"actions":
                    [
                        {"fields": [],
                         "name": "ready_for_review"
                         }
                    ],
                 "conditions":
                    {"all":
                        [
                            {"operator": "less_than",
                             "value": "100000",
                              "name": "mileage"
                            },
                            {"operator": "greater_than",
                             "value": "2000",
                              "name": "year"
                             }
                        ]
                    }
                }
            ]
            """

    for car in k.postings:
        logging.debug('Running business rules on %s' % car )
        run_all(json.loads(rules),
                CarVariables,
                CarActions,
                stop_on_first_trigger=False)

@lorddaren
Copy link
Author

After posting the last output I realized my mistake. I was failing to actually pass the "car" object to the variables and actions.

vrsandeep pushed a commit to vrsandeep/business-rules that referenced this issue May 31, 2019
* Engine change to return only successful conditions

* Tests fixed

* Test cases for new logic for check conditions result

* Additional case added

* Small change in conditions values. Don't affect the test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants