Skip to content

Commit 51de4f4

Browse files
INTEG-3268 - fix bug in trusted_activities iter_all
1 parent c6b6867 commit 51de4f4

4 files changed

Lines changed: 50 additions & 6 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
how a consumer would use the library or CLI tool (e.g. adding unit tests, updating documentation, etc) are not captured
1010
here.
1111

12-
## Unreleased
12+
## 2.12.4 - 2026-09-29
13+
- Fixed an issue where listing trusted activities in some cases would loop infinitely.
1314

14-
### 2.12.3 - 2026-09-11
15+
## 2.12.3 - 2026-09-11
1516
- The `retry_on_rate_limit` setting, which controls whether the SDK will retry 429 responses. Defaults to on, retrying most 429 responses up to 3 times. Set this to False on SDK initialization if you wish to manually handle retrying 429 responses. When enabled, if retries are exhausted, requests.exceptions.RetryError will be raised.
1617

1718
## 2.12.2 - 2026-06-22

‎src/_incydr_sdk/__version__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# SPDX-FileCopyrightText: 2022-present Code42 Software <integrations@code42.com>
22
#
33
# SPDX-License-Identifier: MIT
4-
__version__ = "2.12.3"
4+
__version__ = "2.12.4"

‎src/_incydr_sdk/trusted_activities/client.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def iter_all(
104104
"""
105105

106106
page_size = page_size or self._parent.settings.page_size
107+
last_page_ids = set()
107108
for page_num in count(1):
108109
page = self.get_page(
109110
page_num=page_num,
@@ -112,8 +113,14 @@ def iter_all(
112113
sort_key=sort_key,
113114
sort_direction=sort_direction,
114115
)
115-
yield from page.trusted_activities
116-
if len(page.trusted_activities) < page_size:
116+
results_to_yield = [
117+
x for x in page.trusted_activities if x.activity_id not in last_page_ids
118+
]
119+
yield from results_to_yield
120+
last_page_ids = {x.activity_id for x in page.trusted_activities}
121+
if (len(page.trusted_activities) < page_size) or (
122+
len(results_to_yield) < page_size
123+
):
117124
break
118125

119126
def add_domain(

‎tests/test_trusted_activities.py‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
],
4444
}
4545
],
46-
"activityId": "1324",
46+
"activityId": "13245",
4747
"isHighValueSource": True,
4848
"description": "This is a description",
4949
"principalType": "API_KEY",
@@ -142,6 +142,42 @@ def test_iter_all_when_default_params_returns_expected_data(
142142
assert total_trusted_activities == 2
143143

144144

145+
def test_iter_all_when_page_repeats_returns_expected_data(
146+
httpserver_auth: HTTPServer,
147+
):
148+
query_1 = {
149+
"page_num": 1,
150+
"page_size": 2,
151+
}
152+
query_2 = {"page_num": 2, "page_size": 2}
153+
154+
trusted_activities_data_1 = {
155+
"trustedActivities": [TEST_TRUSTED_ACTIVITY_1, TEST_TRUSTED_ACTIVITY_2],
156+
"totalCount": 2,
157+
}
158+
159+
httpserver_auth.expect_request(
160+
"/v2/trusted-activities", method="GET", query_string=urlencode(query_1)
161+
).respond_with_json(trusted_activities_data_1)
162+
163+
httpserver_auth.expect_request(
164+
"/v2/trusted-activities", method="GET", query_string=urlencode(query_2)
165+
).respond_with_json(trusted_activities_data_1)
166+
167+
client = Client()
168+
iterator = client.trusted_activities.v2.iter_all(page_size=2)
169+
total_trusted_activities = 0
170+
expected_trusted_activities = [TEST_TRUSTED_ACTIVITY_1, TEST_TRUSTED_ACTIVITY_2]
171+
172+
for item in iterator:
173+
total_trusted_activities += 1
174+
assert isinstance(item, TrustedActivity)
175+
assert item.json() == json.dumps(
176+
expected_trusted_activities.pop(0), separators=(",", ":")
177+
)
178+
assert total_trusted_activities == 2
179+
180+
145181
def test_add_domain_when_default_params_returns_expected_data(
146182
httpserver_auth: HTTPServer,
147183
):

0 commit comments

Comments
 (0)