Skip to content

Commit 8e2849a

Browse files
authored
[ES-244938] Fix pipelines list pagination (#417)
The `pagination` request and response property is now deprecated. Instead, the nested properties from inside `pagination` have been elevated to the top level (where `pagination` used to reside). This PR fixes the pagination-related property access so that more than one page of pipelines are returned. ### Before ```bash $ databricks pipelines list | jq '. | length' 25 ``` ### After ```bash $ databricks pipelines list | jq '. | length' 311 ```
1 parent 6c429d4 commit 8e2849a

2 files changed

Lines changed: 17 additions & 19 deletions

File tree

databricks_cli/pipelines/api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,20 @@ def list(self, headers=None):
6363
def call(page_token=None, max_results=None, order_by=None):
6464
_data = {}
6565
if page_token:
66-
_data["pagination.page_token"] = page_token
66+
_data["page_token"] = page_token
6767
if max_results:
68-
_data["pagination.max_results"] = max_results
68+
_data["max_results"] = max_results
6969
if order_by:
70-
_data["pagination.order_by"] = order_by
70+
_data["order_by"] = order_by
7171

7272
return self.client.client.perform_query(
7373
'GET', '/pipelines', data=_data, headers=headers)
7474

7575
response = call()
7676
pipelines = response.get("statuses", [])
7777

78-
while "next_page_token" in response.get("pagination", {}):
79-
response = call(page_token=response["pagination"]["next_page_token"])
78+
while "next_page_token" in response:
79+
response = call(page_token=response["next_page_token"])
8080
pipelines.extend(response.get("statuses", []))
8181
return pipelines
8282

tests/pipelines/test_api.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def test_library_object_serialization_deserialization():
330330

331331
def test_list(pipelines_api):
332332
client_mock = pipelines_api.client.client.perform_query
333-
client_mock.side_effect = [{"statuses": [], "pagination": {}}]
333+
client_mock.side_effect = [{"statuses": []}]
334334

335335
pipelines_api.list()
336336
assert client_mock.call_count == 1
@@ -341,13 +341,13 @@ def test_list(pipelines_api):
341341

342342
def test_list_with_page_token(pipelines_api):
343343
client_mock = pipelines_api.client.client.perform_query
344-
client_mock.side_effect = [{"statuses": [], "pagination": {"next_page_token": "a"}},
345-
{"statuses": [], "pagination": {}}]
344+
client_mock.side_effect = [{"statuses": [], "next_page_token": "a"},
345+
{"statuses": []}]
346346

347347
pipelines_api.list()
348348
assert client_mock.call_count == 2
349349
client_mock.assert_called_with('GET', '/pipelines',
350-
data={"pagination.page_token": "a"}, headers=None)
350+
data={"page_token": "a"}, headers=None)
351351

352352

353353
def test_list_with_paginated_responses(pipelines_api):
@@ -363,7 +363,7 @@ def test_list_with_paginated_responses(pipelines_api):
363363
'cluster_id': '1024-160918-tees475',
364364
'name': 'Wiki Pipeline',
365365
'health': 'HEALTHY'}],
366-
'pagination': {'next_page_token': 'page2'}
366+
'next_page_token': 'page2'
367367
},
368368
{'statuses': [{'pipeline_id': '3',
369369
'state': 'RUNNING',
@@ -375,9 +375,8 @@ def test_list_with_paginated_responses(pipelines_api):
375375
'cluster_id': '1023-093505-corm4',
376376
'name': 'Jira Automation Staging',
377377
'health': 'HEALTHY'}],
378-
'pagination': {
379-
'next_page_token': 'page3',
380-
'prev_page_token': 'page2'}
378+
'next_page_token': 'page3',
379+
'prev_page_token': 'page2'
381380
},
382381
{'statuses': [{'pipeline_id': '5',
383382
'state': 'FAILED',
@@ -389,8 +388,7 @@ def test_list_with_paginated_responses(pipelines_api):
389388
'cluster_id': '1027-061023-clasp844',
390389
'name': 'Pipeline Demo NYCTaxi',
391390
'health': 'HEALTHY'}],
392-
'pagination': {
393-
'prev_page_token': 'page3'}
391+
'prev_page_token': 'page3'
394392
}
395393
]
396394

@@ -403,10 +401,10 @@ def test_list_with_paginated_responses(pipelines_api):
403401
data={},
404402
headers=None),
405403
mock.call('GET', '/pipelines',
406-
data={"pagination.page_token": "page2"},
404+
data={"page_token": "page2"},
407405
headers=None),
408406
mock.call('GET', '/pipelines',
409-
data={"pagination.page_token": "page3"},
407+
data={"page_token": "page3"},
410408
headers=None)
411409
], any_order=False)
412410

@@ -426,7 +424,7 @@ def test_list_with_no_returned_pipelines(pipelines_api):
426424
'cluster_id': '1024-160918-tees475',
427425
'name': 'Wiki Pipeline',
428426
'health': 'HEALTHY'}],
429-
'pagination': {'next_page_token': 'page2'}
427+
'next_page_token': 'page2'
430428
},
431429
{}
432430
]
@@ -440,7 +438,7 @@ def test_list_with_no_returned_pipelines(pipelines_api):
440438
data={},
441439
headers=None),
442440
mock.call('GET', '/pipelines',
443-
data={"pagination.page_token": "page2"},
441+
data={"page_token": "page2"},
444442
headers=None)
445443
], any_order=False)
446444

0 commit comments

Comments
 (0)