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

Skip to content

Commit cd22af5

Browse files
committed
fix: filter duplicates from previous page during pagination
fixes #2979
1 parent 10ee58a commit cd22af5

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

gitlab/client.py

Lines changed: 17 additions & 1 deletion
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._prev_page_objects = []
1178+
11771179
self._query(url, query_data, **self._kwargs)
11781180
self._get_next = get_next
11791181

@@ -1199,12 +1201,26 @@ def _query(
11991201
self._total: Optional[str] = result.headers.get("X-Total")
12001202

12011203
try:
1202-
self._data: List[Dict[str, Any]] = result.json()
1204+
data: List[Dict[str, Any]] = result.json()
12031205
except Exception as e:
12041206
raise gitlab.exceptions.GitlabParsingError(
12051207
error_message="Failed to parse the server message"
12061208
) from e
12071209

1210+
self._data = []
1211+
for item in data:
1212+
if item in self._prev_page_objects:
1213+
utils.warn(
1214+
message=(
1215+
f"During pagination duplicate object with id "
1216+
f"{item['id']} returned from Gitlab and filtered"
1217+
),
1218+
category=UserWarning,
1219+
)
1220+
continue
1221+
self._data.append(item)
1222+
1223+
self._prev_page_objects = list(self._data)
12081224
self._current = 0
12091225

12101226
@property

0 commit comments

Comments
 (0)