-
Notifications
You must be signed in to change notification settings - Fork 27
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
Prevent validators from getting inserted twice #30
Conversation
Related to this flask-admin issue: pallets-eco/flask-admin#1094 If you override ```field_args``` with your own dict, the changes made to ```kwargs``` in ```convert()``` will also be made to the dict you used to override ```field_args```. The objects that get copied to ```kwargs``` from ```field_args``` are only references, so you need to deepcopy to prevent the issue.
Prevent validators from getting inserted twice
Danke |
I've got an error in my way with deepcode using. PolicyForm = model_form(Policy, Form,
field_args={
'pol_num': dict(validators=[optional()]),
'pol_reg': dict(validators=[optional()])}) Python 3.5 with latest flask, peewee, wtforms and wtfpeewee |
I wasn't able to reproduce the issue in python 2 or 3 using validators.Optional() from wtforms 2.0.2: https://gist.github.com/pawl/9e12f0f8d0d482ece2a7 How are you defining optional()? I can only reproduce the error when I do something like:
|
Sorry, I used modify code... there is full part: from wtforms.validators import required, regexp, length
digits_only = regexp('^\d+$', message='Допустимы только цифры.')
fixed_length = lambda x: length(min=x, max=x)
PolicyForm = model_form(Policy, Form,
field_args={
'pol_num': dict(validators=[digits_only]),
'pol_reg': dict(validators=[digits_only, fixed_length(2)])}) But I tried with |
Hmm, I'm getting the same issue. I guess I'll need to figure out a different way to prevent field_args from getting modified. |
@coleifer set tag please to last commit 0.2.6(?) ;) |
Related to this flask-admin issue: pallets-eco/flask-admin#1094
Edit: See this unit test for an example of the issue: https://github.com/coleifer/wtf-peewee/pull/32/files
If you override
field_args
with your own dict, the changes made tokwargs
inconvert()
will also be made to the dict you used to overridefield_args
. The objects that get copied tokwargs
fromfield_args
are only references, so you need to deepcopy to prevent the issue.