Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b7ac626

Browse files
committed
feat: filter duplicates from previous page during pagination
fixes #2979
1 parent b3834dc commit b7ac626

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

gitlab/client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,8 @@ def __init__(
11741174
# Preserve kwargs for subsequent queries
11751175
self._kwargs = kwargs.copy()
11761176

1177+
self._retrieved_object_ids: set[int] = set()
1178+
11771179
self._query(url, query_data, **self._kwargs)
11781180
self._get_next = get_next
11791181

@@ -1205,6 +1207,18 @@ def _query(
12051207
error_message="Failed to parse the server message"
12061208
) from e
12071209

1210+
duplicate_ids = set(o["id"] for o in self._data) & self._retrieved_object_ids
1211+
if duplicate_ids:
1212+
utils.warn(
1213+
message=(
1214+
f"During pagination duplicate object(s) with id(s) "
1215+
f"{duplicate_ids} returned from Gitlab and filtered"
1216+
),
1217+
category=UserWarning,
1218+
)
1219+
self._data = [o for o in self._data if o["id"] not in duplicate_ids]
1220+
self._retrieved_object_ids.update(o["id"] for o in self._data)
1221+
12081222
self._current = 0
12091223

12101224
@property

0 commit comments

Comments
 (0)