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 validation errors in mixin #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sjamaan
Copy link

@sjamaan sjamaan commented Mar 21, 2019

This has several improvements to how validation errors are raised by the mixin:

  • Use the Django built-in validation error generation to produce better errors:
    • The name of the field that triggered the validation error is used as the error dictionary key if it's a single field. This helps to highlight the field in a frontend.
    • For JSON-based APIs the code field is very useful to determine what is wrong with that particular field, and we rely on this in our project at work
  • When there are failing "standard" uniqueness checks, do not bail out early but merge partial unique validation errors into the standard errors.
  • When there are multiple partially unique indexes that trigger a uniqueness error, all errors are returned instead of just the first.

This builds on #15 so please take a look at that one first.

@sjamaan sjamaan changed the title Better validation errors Improve validation errors in mixin Mar 21, 2019
@sjamaan sjamaan force-pushed the better-validation-errors branch 2 times, most recently from 722f217 to 196fb22 Compare July 22, 2019 11:04
Peter Bex added 3 commits July 22, 2019 13:31
This improves things in the following ways:
- The exception object contains a key to indicate which field is causing the problem.
- The exception object contains a "code"/slug which can be used to programmatically deal with the error.  Very useful in JSON APIs.
- We now use a standard text message that is more in line with the rest of Django (which also means it is translatable)
Just like Django will do in the standard behaviour, we want to ensure
all errors are included.  Therefore, we catch validation errors raised
by Django and merge these with our own.
Instead, evaluate the validation of every unique index.
@sjamaan
Copy link
Author

sjamaan commented Apr 6, 2020

Why no feedback on this PR?

I'm relying on this code in production, and it's essential for us, in case you're doubting the use of this.

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

Successfully merging this pull request may close these issues.

1 participant