pombreda / formalchemy

Automatically exported from code.google.com/p/formalchemy
MIT License
0 stars 0 forks source link

Do not skip validation on non-required fields #117

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When field is not required, but it's value is NULL/None, the validation is
completely skipped. This doesn't allow "allow this to be None only when
some other field is (or is not) set" validation logic.

Presently, validators.required is treated exceptionally which, I believe,
is not a clean solution.

I'd propose extending validators' API contract by adding function attribute
(PEP 232) "accepts_none" which will mean that validator should be called on
"None" values too. This should not break any existing code, but allow more
validation possibilities to a new one.

And maybe add a simple decorator (some @validators.accepts_none) to set
this attribute and make code look more "pythonic"...

Original issue reported on code.google.com by drdae...@gmail.com on 23 Sep 2009 at 5:11

Attachments:

GoogleCodeExporter commented 9 years ago
I've also added a decorator:
http://code.google.com/p/formalchemy/source/browse/formalchemy/validators.py#32

Not tested yet...

Original comment by gael.pas...@gmail.com on 25 Sep 2009 at 5:07

GoogleCodeExporter commented 9 years ago
test added. validators.required use the decorator.

Original comment by gael.pas...@gmail.com on 26 Sep 2009 at 10:47