Skip to content

Commit cf39576

Browse files
committed
fix array slicing
1 parent a365829 commit cf39576

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

django_mongodb/features.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
9898
"model_fields_.test_arrayfield.TestQuerying.test_index_chained",
9999
"model_fields_.test_arrayfield.TestQuerying.test_index_nested",
100100
"model_fields_.test_arrayfield.TestQuerying.test_order_by_slice",
101-
"model_fields_.test_arrayfield.TestQuerying.test_slice",
102-
"model_fields_.test_arrayfield.TestQuerying.test_slice_annotation",
103101
# $lt treats null values as zero.
104102
"model_fields_.test_arrayfield.TestQuerying.test_lt",
105103
"model_fields_.test_arrayfield.TestQuerying.test_len",

django_mongodb/fields/array.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ def get_transform(self, name):
187187
return IndexTransformFactory(index, self.base_field)
188188
try:
189189
start, end = name.split("_")
190-
start = int(start) + 1
191-
end = int(end) # don't add one here because postgres slices are weird
190+
start = int(start)
191+
end = int(end)
192192
except ValueError:
193193
pass
194194
else:
@@ -332,10 +332,8 @@ def __init__(self, start, end, *args, **kwargs):
332332
self.end = end
333333

334334
def as_mql(self, compiler, connection):
335-
lhs, params = compiler.compile(self.lhs)
336-
if not lhs.endswith("]"):
337-
lhs = "(%s)" % lhs
338-
return "%s[%%s:%%s]" % lhs, (*params, self.start, self.end)
335+
lhs_mql = process_lhs(self, compiler, connection)
336+
return {"$slice": [lhs_mql, self.start, self.end]}
339337

340338

341339
class SliceTransformFactory:

0 commit comments

Comments
 (0)