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.
* 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>
* owner: nobody => xafer
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/34338#comment:2>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/16560 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/34338#comment:3>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/34338#comment:4>
* 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>
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>