-
-
Notifications
You must be signed in to change notification settings - Fork 301
Open
Labels
Milestone
Description
There is a problem with the current way of setting default values when using validators.
The method _validate_items
should have no side effect
on the object being validated, inside that method, teh settings
must be read only to perform the validation.
Currently this method calls set twice to set default values and apply cast transformation.
This is causing problems with the inspect
history and is duplicating the calls to set
Proposal
- Stop calling
set
onvalidate_items
- Collect defaults and cast from registered validators
Refactoring
- Stop calling
set
andsetdefault
inside_validate_items
- change this block to
value = settings.get(name, empty)
- On
ValidatorList.register
iterate all validators and register itsdefault
andcast
parameter onsettings._validators_defaults: DynaBox
(OR store it on the instance of ValidatorList itself - On
Settings.get
line change the implementation to raiseKeyError
and then on except lookup theself._validators_defaults
elsedefault
- On line lookup for
cast
also onself._validators_defaults
if not passed directly toget
- On Settings init create an instance of ValidatorsList and then call the register on it, also change ValidatorList init to pass accepted args to register instead of super
pedro-psb and eirnym