1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #30335, #29139 -- Fixed crash when ordering or aggregating over a nested JSONField key transform.

This commit is contained in:
can
2019-04-17 09:24:28 +03:00
committed by Mariusz Felisiak
parent f110de5c04
commit d87bd29c4f
3 changed files with 36 additions and 5 deletions

View File

@@ -14,6 +14,7 @@ from django.db.models.sql.query import Query, get_order_dir
from django.db.transaction import TransactionManagementError
from django.db.utils import DatabaseError, NotSupportedError
from django.utils.deprecation import RemovedInDjango31Warning
from django.utils.hashable import make_hashable
FORCE = object()
@@ -126,9 +127,10 @@ class SQLCompiler:
for expr in expressions:
sql, params = self.compile(expr)
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):
@@ -352,9 +354,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