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

Improve ModelField errors #2075

Merged
merged 3 commits into from Mar 21, 2019
Merged

Improve ModelField errors #2075

merged 3 commits into from Mar 21, 2019

Conversation

noirbizarre
Copy link
Contributor

@noirbizarre noirbizarre commented Mar 21, 2019

This PR test and fixes some error cases on ModelField form field with db.ReferenceField and db.GenericReferenceField:

  • Prevent 'required` error message to hide other ones
  • Adds a lot of specific case more explicit error message
  • Prevent some internal server errors

Fix #2066

@noirbizarre noirbizarre added this to the 1.6.6 milestone Mar 21, 2019
@noirbizarre noirbizarre requested a review from a team March 21, 2019 10:02
Copy link
Contributor

@abulte abulte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏


def pre_validate(self, form):
# If any error happen during process, we raise StopValidation here
# to prevent "DataRequired" validator from clearing errors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that was the tricky part to find !!! 😅

udata/models/__init__.py Outdated Show resolved Hide resolved
@noirbizarre
Copy link
Contributor Author

noirbizarre commented Mar 21, 2019

It took a day to write test_model_field.py (test all error case for all combinations of "required/optionnal form field" + "db.GenericReferenceField/db.ReferenceField" + "all possible errors (at least known to me)".

But I just discovered some existing tests in test_reference_field.py. I need to merge them into test_model_field.py to make tests pass (the PR is missing the choices case)

WTForm error handling is a little bit tricky: the DataRequired validator remove other error messages when triggered. It might happen on some other form field.

@noirbizarre
Copy link
Contributor Author

Done, tests passed

@noirbizarre noirbizarre requested a review from abulte March 21, 2019 10:59
@noirbizarre noirbizarre merged commit 37b979c into opendatateam:master Mar 21, 2019
@noirbizarre noirbizarre deleted the model-field-errors branch March 21, 2019 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Discussions API with invalid id or class: improve error and return 404?
2 participants