-
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
Foreign key error message in WTForms validation #43
Comments
Shouldn't you ensure the object exists before assigning a value to a foreign-key field, though? |
I am talking about validation of incoming POST data that of course should be checked in the frontend, but I cannot guarantee this. |
I don't understand what you're asking for or what the problem is. |
I am trying to make validator for incoming params using wtf-peewee Supposing, I have this objects in database:
and I made a REST api interface to it
Now I want to validate incoming params when creating project, so I added validator:
And when I send wrong region_id that doesn't exist in database, form.errors contains:
As well as when I doesn't send region_id at all:
The question is - can I somehow get error message something like "No region with id = 10" in case when region_id is passed, but object is not found? Thanks! |
Not sure, the field should be raising the message "Not a valid choice". |
It should, but for me it seems that exception raises when sql query does not succeed, on this row: https://github.com/coleifer/wtf-peewee/blob/master/wtfpeewee/fields.py#L264 I don't understand why, with exists() call it should return true or false. |
Is this the same as the issue you just opened, #46 ? Are they related? |
They are related, but I am not sure that this is the same case. In the case of required param with wrong foreign key validation fails as expected but the error message is incorrect. But maybe Exception on DoesNotExist in the get_model() will fix both cases, I don't know. |
When I try to post a new object with foreign key field that doesn't match to any object in the database, I get the same message, as when I don't pass this field at all:
It looks like a bug.
The text was updated successfully, but these errors were encountered: