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

Conversation

@noirbizarre
Copy link
Member

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 opendatateam/etalab Mar 21, 2019
@noirbizarre noirbizarre force-pushed the noirbizarre:model-field-errors branch from b7db915 to e6e824f Mar 21, 2019
Copy link
Member

left a comment

👏


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

This comment has been minimized.

Copy link
@abulte

This comment has been minimized.

Copy link
@noirbizarre

noirbizarre Mar 21, 2019

Author Member

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

udata/models/__init__.py Outdated Show resolved Hide resolved
@noirbizarre

This comment has been minimized.

Copy link
Member Author

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 noirbizarre force-pushed the noirbizarre:model-field-errors branch from e6e824f to 9b54a9a Mar 21, 2019
@noirbizarre

This comment has been minimized.

Copy link
Member Author

commented Mar 21, 2019

Done, tests passed

@noirbizarre noirbizarre requested a review from abulte Mar 21, 2019
@abulte
abulte approved these changes Mar 21, 2019
@noirbizarre noirbizarre merged commit 37b979c into opendatateam:master Mar 21, 2019
3 checks passed
3 checks passed
ci/circleci: assets Your tests passed on CircleCI!
Details
ci/circleci: dist Your tests passed on CircleCI!
Details
ci/circleci: python Your tests passed on CircleCI!
Details
@noirbizarre noirbizarre deleted the noirbizarre:model-field-errors branch Mar 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.