mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[2.2.x] Fixed #30335, #29139 -- Fixed crash when ordering or aggregating over a nested JSONField key transform.
Backport of d87bd29c4f from master.
This commit is contained in:
@@ -17,6 +17,7 @@ from django.db.utils import DatabaseError, NotSupportedError
|
||||
from django.utils.deprecation import (
|
||||
RemovedInDjango30Warning, RemovedInDjango31Warning,
|
||||
)
|
||||
from django.utils.hashable import make_hashable
|
||||
from django.utils.inspect import func_supports_parameter
|
||||
|
||||
FORCE = object()
|
||||
@@ -135,9 +136,10 @@ class SQLCompiler:
|
||||
# wrapping () because they could be removed when a subquery is
|
||||
# the "rhs" in an expression (see Subquery._prepare()).
|
||||
sql = '(%s)' % sql
|
||||
if (sql, tuple(params)) not in seen:
|
||||
params_hash = make_hashable(params)
|
||||
if (sql, params_hash) not in seen:
|
||||
result.append((sql, params))
|
||||
seen.add((sql, tuple(params)))
|
||||
seen.add((sql, params_hash))
|
||||
return result
|
||||
|
||||
def collapse_group_by(self, expressions, having):
|
||||
@@ -361,9 +363,10 @@ class SQLCompiler:
|
||||
# is refactored into expressions, then we can check each part as we
|
||||
# generate it.
|
||||
without_ordering = self.ordering_parts.search(sql).group(1)
|
||||
if (without_ordering, tuple(params)) in seen:
|
||||
params_hash = make_hashable(params)
|
||||
if (without_ordering, params_hash) in seen:
|
||||
continue
|
||||
seen.add((without_ordering, tuple(params)))
|
||||
seen.add((without_ordering, params_hash))
|
||||
result.append((resolved, (sql, params, is_ref)))
|
||||
return result
|
||||
|
||||
|
||||
Reference in New Issue
Block a user