[Django] #34338: Allow to customize the code attribute of ValidationError raised by BaseConstraint.validate

49 views
Skip to first unread message

Django

unread,
Feb 13, 2023, 3:24:07 PM2/13/23
to django-...@googlegroups.com
#34338: Allow to customize the code attribute of ValidationError raised by
BaseConstraint.validate
-----------------------------------------+------------------------
Reporter: xafer | Owner: nobody
Type: New feature | Status: new
Component: Uncategorized | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
It is currently possible to customize the `violation_error_message` of a
`ValidationError` raised by a constraint but not the code.

I'd like to add a new `violation_error_message` parameter to
BaseConstraint to allow to easily add one.

Currently, to achieve the same result, you have to subclass the constraint
to tweak `validate` to catch and reraise the `ValidationError`.

Since the documentation recommends to `Provide a descriptive error code to
the constructor:` when raising a ValidationError in
https://docs.djangoproject.com/en/4.1/ref/forms/validation/#raising-
validationerror , I think it would make sense to provide this possibility
for errors raised by constraints.

If you think it would be a good idea, I'd be happy to work on a PR.

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

Django

unread,
Feb 13, 2023, 11:16:25 PM2/13/23
to django-...@googlegroups.com
#34338: Allow to customize the code attribute of ValidationError raised by
BaseConstraint.validate
-------------------------------------+-------------------------------------

Reporter: xafer | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* cc: Gagaro (added)
* component: Uncategorized => Database layer (models, ORM)
* stage: Unreviewed => Accepted


Comment:

Replying to [ticket:34338 xafer]:


> It is currently possible to customize the `violation_error_message` of a
`ValidationError` raised by a constraint but not the code.
>
> I'd like to add a new `violation_error_message` parameter to
BaseConstraint to allow to easily add one.

Agreed, adding `violation_error_code` sounds like a good idea as we have a
similar mechanism for validators.

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

Django

unread,
Feb 14, 2023, 4:55:41 AM2/14/23
to django-...@googlegroups.com
#34338: Allow to customize the code attribute of ValidationError raised by
BaseConstraint.validate
-------------------------------------+-------------------------------------
Reporter: xafer | Owner: xafer
Type: New feature | Status: assigned

Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by xafer):

* owner: nobody => xafer
* status: new => assigned


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

Django

unread,
Feb 16, 2023, 5:47:22 AM2/16/23
to django-...@googlegroups.com
#34338: Allow to customize the code attribute of ValidationError raised by
BaseConstraint.validate
-------------------------------------+-------------------------------------
Reporter: xafer | Owner: xafer
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/16560 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/34338#comment:3>

Django

unread,
Feb 23, 2023, 4:59:31 AM2/23/23
to django-...@googlegroups.com
#34338: Allow to customize the code attribute of ValidationError raised by
BaseConstraint.validate
-------------------------------------+-------------------------------------
Reporter: xafer | Owner: xafer
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/34338#comment:4>

Django

unread,
Feb 23, 2023, 6:47:42 AM2/23/23
to django-...@googlegroups.com
#34338: Allow to customize the code attribute of ValidationError raised by
BaseConstraint.validate
-------------------------------------+-------------------------------------
Reporter: xafer | Owner: xafer
Type: New feature | Status: closed

Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"5b3d3e400ab9334ba429ca360c9818c6dfc3a51b" 5b3d3e4]:
{{{
#!CommitTicketReference repository=""
revision="5b3d3e400ab9334ba429ca360c9818c6dfc3a51b"
Fixed #34338 -- Allowed customizing code of ValidationError in
BaseConstraint and subclasses.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34338#comment:5>

Django

unread,
Feb 24, 2023, 3:03:03 AM2/24/23
to django-...@googlegroups.com
#34338: Allow to customize the code attribute of ValidationError raised by
BaseConstraint.validate
-------------------------------------+-------------------------------------
Reporter: xafer | Owner: xafer
Type: New feature | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by GitHub <noreply@…>):

In [changeset:"2c428b37ae14b1514cfe1466fd91f01d56799bf4" 2c428b3]:
{{{
#!CommitTicketReference repository=""
revision="2c428b37ae14b1514cfe1466fd91f01d56799bf4"
Refs #34338 -- Fixed isolation of constraints tests.

Regression in 5b3d3e400ab9334ba429ca360c9818c6dfc3a51b.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34338#comment:6>

Reply all
Reply to author
Forward
0 new messages