Type error for valid validation rule and data
I am getting TypeError when I am trying to validate a dict with proper validation rule.
The validation_rule I am using : {'email': 'required|mail', 'password': 'required|min:6'}
The data I am trying to validate : {'deviceSerialNumber': 'dd2114d80437f4ba7aasdf3d6ef02932e2', 'firmwareVersion': '1.01', 'deviceType': 'daylite', 'deviceUuid': 'd7f4ba7a83d63ef02932', 'password': ''}
In this case, the validation should fail, providing validation errors. However, I am getting TypeError.
Traceback :
Traceback (most recent call last):
File "
How I am using validate :
validation_rule = {'email': 'required|mail', 'password': 'required|min:6'} data = {'deviceSerialNumber': 'dd2114d80437f4ba7aasdf3d6ef02932e2', 'firmwareVersion': '1.01', 'deviceType': 'daylite', 'deviceUuid': 'd7f4ba7a83d63ef02932', 'password': ''} from validator import validate validate(data, validation_rule)
The 'mail' rule is not checking if the provided arg is of type(str), which is causing the issue. (In this case, it is of type(None)). I have implemented the check and the issue seems to be resolved. I have created a new branch and fixed the issue, but, I do not have the required permissions to push the commit.
This is the check method in 'mail' rule after fix :
def check(self, arg):
if type(arg) == str and re.search(self.regex, arg) is not None:
return True
self.set_error(f"Expected a Mail, Got: {arg}")
return False
Please accept the commit I am trying to push or add this to the code as a permanent or temp fix (if there is any other better solution) and create the package.
Another possible solution :
def check(self, arg):
if type(arg) != str:
if arg == None:
return True
raise TypeError(
f"Value should be of type str. {arg} of type {type(arg)} passed."
)
if type(arg) == str and re.search(self.regex, arg) is not None:
return True