-
Notifications
You must be signed in to change notification settings - Fork 71
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
DelimitedDigitsPostalCode does not implement if_missing #129
Comments
I just have did double check and found that in formencode 1.3.1 validator from formencode import national, Schema, validators
class TestValidator(Schema):
allow_extra_fields = True
filter_extra_fields = True
postal_code_5_digits = national.DelimitedDigitsPostalCode(5, None, not_empty=False, if_missing='')
print(TestValidator.to_python({}))
# {'postal_code_5_digits': ''} is printed But # from file formencode/national.py
def USPostalCode(*args, **kw):
"""
US Postal codes (aka Zip Codes).
::
>>> uspc = USPostalCode()
>>> uspc.to_python('55555')
'55555'
>>> uspc.to_python('55555-5555')
'55555-5555'
>>> uspc.to_python('5555')
Traceback (most recent call last):
...
Invalid: Please enter a zip code (5 digits)
"""
return Any(DelimitedDigitsPostalCode(5, None, *args, **kw),
DelimitedDigitsPostalCode([5, 4], '-', *args, **kw)) So the root issue is in validator class # from file formencode/compound.py
class All(CompoundValidator):
# <...>
@property
def if_missing(self):
for validator in self.validators:
v = validator.if_missing
if v is not NoDefault:
return v
return NoDefault Meanwhile validator class Looks like both compound validators -- |
Thanks for pointing that out. I should have taken the time to research before opening the issue, my mistake. |
For some reason DelimitedDigitsPostalCode doesn't implement if_missing. I am wondering if this was done on purpose.
A quick traversal through the classes
FancyValidator sets if_missing to NoDefault, but Regex and DelimitedDigitPostalCode do not override it with anything.
A workaround is to just manually set postal_code_schema_validation_field.if_missing = None in the schema
Thanks to Vsevolod Kulaga for pointing all of this out in https://stackoverflow.com/questions/44387896/formencode-is-ignoring-if-missing/44397189#44397189
The text was updated successfully, but these errors were encountered: