[Django] #31306: Raise ValidationError on first failure

7 views
Skip to first unread message

Django

unread,
Feb 24, 2020, 3:42:22 PM2/24/20
to django-...@googlegroups.com
#31306: Raise ValidationError on first failure
-------------------------------------+-------------------------------------
Reporter: Doug | Owner: nobody
Fultz |
Type: New | Status: new
feature |
Component: Database | Version: 3.0
layer (models, ORM) | Keywords: feature request
Severity: Normal | validators
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Currently field validators are executed in order and any exceptions are
collected before raising a single ValidationError for that field.
https://github.com/django/django/blob/master/django/db/models/fields/__init__.py#L600

I have identified a use case where a validator may reach our to an
external service or be very expensive to run, compared to other validators
on the field. It would help increase performance and decrease load on
other services if there was an option for field validation to fail on the
first exception and prevent subsequent validators from being executed.

An example might be a validator that looks like
{{{#!python
...
validators = [RegexValidator(r'\w'), ExpensiveExists]
}}}

Where the regex validator is fast and runs locally while ExpensiveExists
calls out to an external service. In this case, we would want validation
to fail on the regex and not call the expensive validation.

--
Ticket URL: <https://code.djangoproject.com/ticket/31306>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 25, 2020, 1:57:52 AM2/25/20
to django-...@googlegroups.com
#31306: Raise ValidationError on first failure.
-------------------------------------+-------------------------------------
Reporter: Doug Fultz | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: feature request | Triage Stage:
validators | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: new => closed
* resolution: => wontfix


Comment:

Thanks for this ticket, however you use case is quite niche, IMO. You can
always use a custom field and override `run_validators()`.

--
Ticket URL: <https://code.djangoproject.com/ticket/31306#comment:1>

Django

unread,
Mar 4, 2020, 5:27:21 AM3/4/20
to django-...@googlegroups.com
#31306: Raise ValidationError on first failure.
-------------------------------------+-------------------------------------
Reporter: Doug Fultz | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: feature request | Triage Stage:
validators | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Adam (Chainz) Johnson):

It's also bad user experience to hide an error until others have been
fixed. Django's run-them-all behaviour is the most user friendly.

--
Ticket URL: <https://code.djangoproject.com/ticket/31306#comment:2>

Reply all
Reply to author
Forward
0 new messages