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
[RFC] Stop setting default value inside validate method #981
Comments
This will fix #974 - So the implementation here must also cover the problem reported there |
This was referenced Aug 17, 2023
rochacbruno
added a commit
that referenced
this issue
Aug 23, 2023
Default will be declared on validators but applied only on get method Fix #981
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is a problem with the current way of setting default values when using validators.
The method
_validate_items
should have noside effect
on the object being validated, inside that method, tehsettings
must be read only to perform the validation.Currently this method calls set twice to set default values and apply cast transformation.
here and here
This is causing problems with the
inspect
history and is duplicating the calls toset
Proposal
set
onvalidate_items
Refactoring
set
andsetdefault
inside_validate_items
value = settings.get(name, empty)
ValidatorList.register
iterate all validators and register itsdefault
andcast
parameter onsettings._validators_defaults: DynaBox
(OR store it on the instance of ValidatorList itselfSettings.get
line change the implementation to raiseKeyError
and then on except lookup theself._validators_defaults
elsedefault
cast
also onself._validators_defaults
if not passed directly toget
The text was updated successfully, but these errors were encountered: