Skip to content

fix(LoopBase): handle stop=0 in __getitem__ slice - #3762

Open
astitvabajpai wants to merge 1 commit into
milvus-io:masterfrom
astitvabajpai:fix/3543-loopbase-getitem-stop-zero
Open

fix(LoopBase): handle stop=0 in __getitem__ slice#3762
astitvabajpai wants to merge 1 commit into
milvus-io:masterfrom
astitvabajpai:fix/3543-loopbase-getitem-stop-zero

Conversation

@astitvabajpai

Copy link
Copy Markdown

Summary

Fixes #3543

LoopBase.__getitem__ used if item.stop to decide the slice end, but 0 is falsy in Python. This caused page[0:0] to silently return all elements instead of an empty list, breaking pagination edge cases in SearchPage and the search iterator.


Root Cause

In pymilvus/client/abstract.py, the LoopBase.__getitem__ method had:

_end = min(item.stop, self.__len__()) if item.stop else self.__len__()

@sre-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: astitvabajpai
To complete the pull request process, please assign czs007 after the PR has been reviewed.
You can assign the PR to them by writing /assign @czs007 in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sre-ci-robot

Copy link
Copy Markdown

Welcome @astitvabajpai! It looks like this is your first PR to milvus-io/pymilvus 🎉

if item.stop treated stop=0 as falsy, causing page[0:0] to return
all elements instead of an empty list.

Change the guard to if item.stop is not None so a legitimate stop
value of 0 is respected while a missing stop (None) still falls back
to the full length.

Adds regression test test_loop_base_getitem_slice_stop_zero covering
the reported edge cases.

Fixes milvus-io#3543

Signed-off-by: astitvabajpai <astitvabajpai22@gmail.com>
@astitvabajpai
astitvabajpai force-pushed the fix/3543-loopbase-getitem-stop-zero branch from de5771e to da46493 Compare August 16, 2026 11:07
@mergify mergify Bot added dco-passed and removed needs-dco labels Aug 16, 2026
@mergify

mergify Bot commented Aug 16, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: LoopBase.__getitem__ treats stop=0 as falsy, returning all elements instead of empty list

2 participants