colander
colander copied to clipboard
Boolean inputs lower-cased before being compared to true_values and false_values
When the parameters true_values
and false_values
are set for a boolean, inputs to fields of that type are checked against the values in those lists, however those input values are being lower cased (see the code here) and the true and false list values are not, leading this code:
node.typ = colander.Boolean(
false_choices=('false', 'N', '0'),
true_choices=('true', 'Y')
)
to produce this error:
"Y" is neither in ('false', 'N', '0') nor in ('true', 'Y')
I would suggest that either the lower casing of boolean inputs should be removed, or if these settings are intended to be case insensitive, lowercase the true and false list values before their comparison to inputs and add a note to the docs explaining that case is ignored.
So the assumption that case is ignored has been in the boolean type since it was introduced. See https://github.com/Pylons/colander/commit/0dcfe99718ffb52bfa32b7215ac782d92a031abc#diff-f597877dc5d654c8b79597aab87d7365R397. The line was blurred when this "Case is ignored" docstring was removed in https://github.com/Pylons/colander/commit/94ca41f3b6b76359295eba1548cafb3ac9e42f76.
I think that the assumption that case is ignored should be retained and that the docstring should be made more clear. Unfortunately it isn't clear to me at all how this can be rationalized with the latest commit in which it adds support for arbitrary languages and what that means for case-insensitivity.
Anyway I don't have the right answer here but wanted to document what I found after a little dive into history. I'd argue again that the docstring should just be updated instead of changing the behavior.