Skip to content
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

Wrong foreign key field pass the validation if the field is optional #46

Open
AnastassiyaP opened this issue Aug 23, 2018 · 5 comments
Open

Comments

@AnastassiyaP
Copy link

It happens because get_model doesn't fail on DoesNotExist https://github.com/coleifer/wtf-peewee/blob/master/wtfpeewee/fields.py#L229

Could you please change this behavior?

@coleifer
Copy link
Owner

coleifer commented Aug 23, 2018

"It happens" -- what happens? Can you clarify? What are you wanting to happen?

@AnastassiyaP AnastassiyaP changed the title Wrong foreign key field pass the form if the field is optional Wrong foreign key field pass the validation if the field is optional Aug 24, 2018
@AnastassiyaP
Copy link
Author

Happens that form.validate() returns True and then on saving the object, I get database error because foreign key constraint fails.
I want to get an error like "Object does not exist" if I pass the wrong param

@AnastassiyaP
Copy link
Author

I have another issue with this
When I try to use custom validators on foreign key field, I get an error, because wtf-peewee redefines field.data as a property here https://github.com/coleifer/wtf-peewee/blob/master/wtfpeewee/fields.py#L233
So field.validate() tries to get object.data to validate, and gets the peewee object, if it exists. And empty string if does not.

@coleifer
Copy link
Owner

Hmm... As I recall the way wtforms manages field data and handles validation was really weird and I had to make many workarounds. Not sure? Can you create a failing test-case in the test-suite?

@AnastassiyaP
Copy link
Author

Yes, sure.
Take a look, please, I created the commit that illustrates this two situations: https://github.com/coleifer/wtf-peewee/compare/master...AnastassiyaP:test_opt_fk?expand=1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants