Skip to content

Commit c65528c

Browse files
committed
fix for other resources
1 parent eb72f59 commit c65528c

7 files changed

Lines changed: 19 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
## Bug Fixes
44

5-
### Variables
6-
* Fixed `variables.list()` / `variables.list_all()` infinite-looping on workspaces with 100 or more variables, so they are now fetched with a single request. The generic list helper also treats any response without `meta.pagination` as a single complete page, preventing the same loop on other non-paginated endpoints. [#181](https://github.com/hashicorp/python-tfe/issues/181)
5+
### Pagination
6+
* Fixed `list_*` infinite-looping for API call which are non paginated, so they are now fetched with a single request. The generic list helper also treats any response without `meta.pagination` as a single complete page, preventing the same loop on other non-paginated endpoints. [#181](https://github.com/hashicorp/python-tfe/issues/181)
77

88

99
# Released

src/pytfe/resources/no_code_module.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,12 @@ def read_variables(
255255
if not valid_string(version):
256256
raise InvalidVersionError()
257257

258+
# module-variables is not paginated; fetch the full set in one request.
258259
path = (
259260
f"/api/v2/no-code-modules/{no_code_module_id}"
260261
f"/versions/{version}/module-variables"
261262
)
262-
for item in self._list(path):
263+
for item in self._list(path, paginated=False):
263264
attrs = item.get("attributes") or {}
264265
yield RegistryModuleVariable.model_validate(
265266
{

src/pytfe/resources/projects.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,9 @@ def list_effective_tag_bindings(
320320
if not valid_string_id(project_id):
321321
raise ValueError("Project ID is required and must be valid")
322322

323+
# effective-tag-bindings is not paginated.
323324
path = f"/api/v2/projects/{project_id}/effective-tag-bindings"
324-
for item in self._list(path):
325+
for item in self._list(path, paginated=False):
325326
attr = item.get("attributes", {}) or {}
326327
links = item.get("links", {}) or {}
327328
yield EffectiveTagBinding(

src/pytfe/resources/run_event.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ def list(
2626
params: dict[str, Any] = {}
2727
if options and options.include:
2828
params["include"] = ",".join(options.include)
29+
# The run-events endpoint is not paginated; fetch the full set in one request.
2930
path = f"/api/v2/runs/{run_id}/run-events"
30-
for item in self._list(path, params=params):
31+
for item in self._list(path, params=params, paginated=False):
3132
attrs = item.get("attributes", {})
3233
attrs["id"] = item.get("id")
3334
yield RunEvent.model_validate(attrs)

src/pytfe/resources/workspaces.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,9 @@ def list_tag_bindings(self, workspace_id: str) -> Iterator[TagBinding]:
744744
if not valid_string_id(workspace_id):
745745
raise InvalidWorkspaceIDError()
746746

747+
# tag-bindings is not paginated.
747748
path = f"/api/v2/workspaces/{workspace_id}/tag-bindings"
748-
for item in self._list(path):
749+
for item in self._list(path, paginated=False):
749750
attr = item.get("attributes", {}) or {}
750751
yield TagBinding(
751752
id=item.get("id"),
@@ -759,8 +760,9 @@ def list_effective_tag_bindings(
759760
if not valid_string_id(workspace_id):
760761
raise InvalidWorkspaceIDError()
761762

763+
# effective-tag-bindings is not paginated.
762764
path = f"/api/v2/workspaces/{workspace_id}/effective-tag-bindings"
763-
for item in self._list(path):
765+
for item in self._list(path, paginated=False):
764766
attr = item.get("attributes", {}) or {}
765767
yield EffectiveTagBinding(
766768
id=item.get("id", ""),

tests/units/test_run_events.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def test_list_run_events_success(self, run_events_service):
7272
mock_list.assert_called_once_with(
7373
"/api/v2/runs/run-123/run-events",
7474
params={"include": "actor"},
75+
paginated=False,
7576
)
7677

7778
# Verify results
@@ -113,6 +114,7 @@ def test_list_run_events_with_multiple_includes(self, run_events_service):
113114
mock_list.assert_called_once_with(
114115
"/api/v2/runs/run-456/run-events",
115116
params={"include": "actor,comment"},
117+
paginated=False,
116118
)
117119

118120
assert len(results) == 1
@@ -140,6 +142,7 @@ def test_list_run_events_no_options(self, run_events_service):
140142
mock_list.assert_called_once_with(
141143
"/api/v2/runs/run-789/run-events",
142144
params={},
145+
paginated=False,
143146
)
144147

145148
assert len(results) == 1

tests/units/test_workspaces.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,10 +1040,11 @@ def test_list_tag_bindings_basic(self, workspaces_service, mock_transport):
10401040
tag_bindings = list(workspaces_service.list_tag_bindings("ws-123"))
10411041

10421042
# Verify API call
1043+
# tag-bindings is non-paginated: a single request with no page params.
10431044
mock_transport.request.assert_called_once_with(
10441045
"GET",
10451046
"/api/v2/workspaces/ws-123/tag-bindings",
1046-
params={"page[number]": 1, "page[size]": 100},
1047+
params={},
10471048
)
10481049

10491050
# Verify returned data
@@ -1096,10 +1097,11 @@ def test_list_effective_tag_bindings_basic(
10961097
)
10971098

10981099
# Verify API call
1100+
# effective-tag-bindings is non-paginated: one request, no page params.
10991101
mock_transport.request.assert_called_once_with(
11001102
"GET",
11011103
"/api/v2/workspaces/ws-123/effective-tag-bindings",
1102-
params={"page[number]": 1, "page[size]": 100},
1104+
params={},
11031105
)
11041106

11051107
# Verify returned data

0 commit comments

Comments
 (0)