CSenshi / Validator

Easy-to-use, Highly Configurable Python Data Validator. Inspired by Laravel Validator
https://pypi.org/project/validator/
MIT License
46 stars 23 forks source link

Validator crashes when property is missing from request dict #122

Closed dolohow closed 3 years ago

dolohow commented 3 years ago

Bug Description: Validator crashes when property is missing from request dict

Expected Behavior: Validator returns errors stating that property is missing from dicgt

Code Fragment:

rules = {
  'user_id': 'required|mail'
}

result, _, errors = validate({'userid': 'asdf'}, rules, return_info=True)

Error Fragment:

  File "/[removed]/__init__.py", line 16, in function_renamed
    result, _, errors = validate({'userid': 'asdf'}, rules, return_info=True)
  File "/[removed]/lib/python3.9/site-packages/validator/validator.py", line 82, in validate
    result = val.validate()
  File "/[removed]/lib/python3.9/site-packages/validator/validator.py", line 31, in validate
    rw.run()
  File "/[removed]/lib/python3.9/site-packages/validator/rules_wrapper.py", line 27, in run
    rpv_result = rpv.execute()
  File "/[removed]/lib/python3.9/site-packages/validator/rule_pipe_validator.py", line 17, in execute
    if not rule(self.data):
  File "/[removed]/lib/python3.9/site-packages/validator/rules_src/__init__.py", line 15, in __call__
    result = self.check(arg)
  File "/[removed]/lib/python3.9/site-packages/validator/rules_src/mail.py", line 28, in check
    if re.search(self.regex, arg) is not None:
  File "/usr/lib/python3.9/re.py", line 201, in search
    return _compile(pattern, flags).search(string)
CSenshi commented 3 years ago

Thank you for bug reporting. Currently we stopped development, but in a few weeks we will be back.

As for this bug at first we thought it would be better to throw error in this case.

Reason is that this library will be used in small products before we reach version 1.X and while in development this error will most likely occur because of some typos and users will be able to debug easily.

Afterwards we think of ignoring such rules that are not in request dictionary and not throwing error.