Re: [Django] #34319: Model.validate_constraints() crashes when constraint's validate() raises ValidationError without a code. (was: ValidationError handling during model.validate_constraints)

4 views
Skip to first unread message

Django

unread,
Feb 8, 2023, 1:40:51 AM2/8/23
to django-...@googlegroups.com
#34319: Model.validate_constraints() crashes when constraint's validate() raises
ValidationError without a code.
-------------------------------------+-------------------------------------
Reporter: Mateusz Kurowski | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: Model, | Triage Stage: Accepted
validate_constraints, |
ValidationError, code, message |
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)
* type: Cleanup/optimization => Bug
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


Comment:

Replying to [ticket:34319 Mateusz Kurowski]:
> This wont work because:
>
> {{{
> 1425, in validate_constraints
> if e.code == "unique" and len(constraint.fields) == 1:
> ^^^^^^
> AttributeError: 'ValidationError' object has no attribute 'code'
> }}}

This is a regression in 667105877e6723c6985399803a364848891513cc, that we
should fix.

> Maybe all unique constraints should allow raising validation error for
specific field like ?

I don't think that adding extra arguments is a step forward here, we
should be able to recognized violated fields by inspecting `expression`,
see #34007.

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

Reply all
Reply to author
Forward
0 new messages