From 2fd755b361d3da2cd0440fc9839feb2bb69b027b Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Wed, 8 Feb 2023 16:38:55 +0100 Subject: Fixed #34319 -- Fixed Model.validate_constraints() crash on ValidationError with no code. Thanks Mateusz Kurowski for the report. Regression in 667105877e6723c6985399803a364848891513cc. --- django/db/models/base.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'django') diff --git a/django/db/models/base.py b/django/db/models/base.py index 06bab385a3..344508e0e2 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) -- cgit v1.3