1
0
mirror of https://github.com/django/django.git synced 2025-10-24 22:26:08 +00:00

Fixed #34285 -- Fixed index/slice lookups on filtered aggregates with ArrayField.

Thanks Simon Charette for the review.
This commit is contained in:
Nils VAN ZUIJLEN
2023-02-06 22:46:44 +01:00
committed by Mariusz Felisiak
parent 4403432b75
commit ae1fe72e9b
2 changed files with 49 additions and 2 deletions

View File

@@ -325,7 +325,9 @@ class IndexTransform(Transform):
def as_sql(self, compiler, connection):
lhs, params = compiler.compile(self.lhs)
return "%s[%%s]" % lhs, params + [self.index]
if not lhs.endswith("]"):
lhs = "(%s)" % lhs
return "%s[%%s]" % lhs, (*params, self.index)
@property
def output_field(self):
@@ -349,7 +351,9 @@ class SliceTransform(Transform):
def as_sql(self, compiler, connection):
lhs, params = compiler.compile(self.lhs)
return "%s[%%s:%%s]" % lhs, params + [self.start, self.end]
if not lhs.endswith("]"):
lhs = "(%s)" % lhs
return "%s[%%s:%%s]" % lhs, (*params, self.start, self.end)
class SliceTransformFactory: