-
Notifications
You must be signed in to change notification settings - Fork 671
fix: filter duplicates from previous page during pagination #2989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1167,13 +1167,17 @@ def __init__( | |||||||||||
url: str, | ||||||||||||
query_data: Dict[str, Any], | ||||||||||||
get_next: bool = True, | ||||||||||||
dedupe: bool = True, | ||||||||||||
**kwargs: Any, | ||||||||||||
) -> None: | ||||||||||||
self._gl = gl | ||||||||||||
|
||||||||||||
# Preserve kwargs for subsequent queries | ||||||||||||
self._kwargs = kwargs.copy() | ||||||||||||
|
||||||||||||
self._dedupe = dedupe | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
self._retrieved_object_ids: set[int] = set() | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (to go with the
Suggested change
|
||||||||||||
|
||||||||||||
self._query(url, query_data, **self._kwargs) | ||||||||||||
self._get_next = get_next | ||||||||||||
|
||||||||||||
|
@@ -1205,6 +1209,21 @@ def _query( | |||||||||||
error_message="Failed to parse the server message" | ||||||||||||
) from e | ||||||||||||
|
||||||||||||
if self._dedupe: | ||||||||||||
duplicate_ids = ( | ||||||||||||
set(o["id"] for o in self._data) & self._retrieved_object_ids | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another issue, as you can see from all the failing tests: we're not actually guaranteed to have This makes me think it would almost be better to do this in python-gitlab/gitlab/mixins.py Lines 248 to 250 in 541a7e3
|
||||||||||||
) | ||||||||||||
if duplicate_ids: | ||||||||||||
Comment on lines
+1213
to
+1216
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can shorten this and use a set comprehension directly:
Suggested change
|
||||||||||||
utils.warn( | ||||||||||||
message=( | ||||||||||||
f"During pagination duplicate object(s) with id(s) " | ||||||||||||
f"{duplicate_ids} returned from Gitlab and filtered" | ||||||||||||
), | ||||||||||||
category=UserWarning, | ||||||||||||
) | ||||||||||||
self._data = [o for o in self._data if o["id"] not in duplicate_ids] | ||||||||||||
self._retrieved_object_ids.update(o["id"] for o in self._data) | ||||||||||||
|
||||||||||||
self._current = 0 | ||||||||||||
|
||||||||||||
@property | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can just go with this in case some newbies get confused :)