summaryrefslogtreecommitdiff
path: root/django/db/models
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-02-08 16:38:55 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-02-08 16:39:53 +0100
commit836ae73a8962876a3beb98bc711fa397d700c82f (patch)
tree43b2832783a9fb1b03bc2cd120a1c6fb1b123c28 /django/db/models
parent1f193f7f56d0f83c188dca8b03266fbaa339d0f5 (diff)
[4.2.x] Fixed #34319 -- Fixed Model.validate_constraints() crash on ValidationError with no code.
Thanks Mateusz Kurowski for the report. Regression in 667105877e6723c6985399803a364848891513cc. Backport of 2fd755b361d3da2cd0440fc9839feb2bb69b027b from main
Diffstat (limited to 'django/db/models')
-rw-r--r--django/db/models/base.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py
index 8c8a74158d..493831759a 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -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)