1
0
mirror of https://github.com/django/django.git synced 2025-10-24 22:26:08 +00:00

Fixed #34319 -- Fixed Model.validate_constraints() crash on ValidationError with no code.

Thanks Mateusz Kurowski for the report.

Regression in 667105877e.
This commit is contained in:
Mariusz Felisiak
2023-02-08 16:38:55 +01:00
committed by GitHub
parent 69069a443a
commit 2fd755b361
3 changed files with 27 additions and 3 deletions

View File

@@ -1444,7 +1444,10 @@ class Model(AltersData, metaclass=ModelBase):
try:
constraint.validate(model_class, self, exclude=exclude, using=using)
except ValidationError as e:
if e.code == "unique" and len(constraint.fields) == 1:
if (
getattr(e, "code", None) == "unique"
and len(constraint.fields) == 1
):
errors.setdefault(constraint.fields[0], []).append(e)
else:
errors = e.update_error_dict(errors)