summaryrefslogtreecommitdiff
path: root/django/db/models
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-01-26 09:31:40 +0100
committerGitHub <noreply@github.com>2023-01-26 09:31:40 +0100
commit2b1242abb3989f5d74e787b09132d01bcbee5b55 (patch)
treedcef5dace32b0e4946dbfe1dbc18cf027a2d1122 /django/db/models
parent882f99031e6e447384bfe22044cc980567d2f40d (diff)
downloaddjango-2b1242abb3989f5d74e787b09132d01bcbee5b55.tar.gz
Fixed #34291 -- Fixed Meta.constraints validation crash on UniqueConstraint with ordered expressions.
Thanks Dan F for the report. Bug in 667105877e6723c6985399803a364848891513cc.
Diffstat (limited to 'django/db/models')
-rw-r--r--django/db/models/constraints.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/django/db/models/constraints.py b/django/db/models/constraints.py
index 179cfd2a18..746d34d115 100644
--- a/django/db/models/constraints.py
+++ b/django/db/models/constraints.py
@@ -3,7 +3,7 @@ from types import NoneType
from django.core.exceptions import FieldError, ValidationError
from django.db import connections
-from django.db.models.expressions import Exists, ExpressionList, F
+from django.db.models.expressions import Exists, ExpressionList, F, OrderBy
from django.db.models.indexes import IndexExpression
from django.db.models.lookups import Exact
from django.db.models.query_utils import Q
@@ -339,10 +339,12 @@ class UniqueConstraint(BaseConstraint):
meta=model._meta, exclude=exclude
).items()
}
- expressions = [
- Exact(expr, expr.replace_expressions(replacements))
- for expr in self.expressions
- ]
+ expressions = []
+ for expr in self.expressions:
+ # Ignore ordering.
+ if isinstance(expr, OrderBy):
+ expr = expr.expression
+ expressions.append(Exact(expr, expr.replace_expressions(replacements)))
queryset = queryset.filter(*expressions)
model_class_pk = instance._get_pk_val(model._meta)
if not instance._state.adding and model_class_pk is not None: