Skip to content

Commit 085456e

Browse files
committed
feat: make refresh consistent between endpoints
Workbooks.refresh correctly accepted both an id string and a WorkbookItem to handle triggering refreshes. Datasources.refresh technically accepted both, but the type annotations did not reflect that. Flows.refresh only accepted a FlowItem, but will now accept a flow_id. This eliminates the need to create otherwise hollow FlowItems to pass to the refresh method when you otherwise have the id.
1 parent d065506 commit 085456e

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

tableauserverclient/server/endpoint/datasources_endpoint.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,16 +375,16 @@ def update_connections(
375375
return connection_items
376376

377377
@api(version="2.8")
378-
def refresh(self, datasource_item: DatasourceItem, incremental: bool = False) -> JobItem:
378+
def refresh(self, datasource_item: Union[DatasourceItem, str], incremental: bool = False) -> JobItem:
379379
"""
380380
Refreshes the extract of an existing workbook.
381381
382382
REST API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_jobs_tasks_and_schedules.htm#run_extract_refresh_task
383383
384384
Parameters
385385
----------
386-
workbook_item : WorkbookItem | str
387-
The workbook item or workbook ID.
386+
workbook_item : DatasourceItem | str
387+
The datasource item or datasource ID.
388388
incremental: bool
389389
Whether to do a full refresh or incremental refresh of the extract data
390390

tableauserverclient/server/endpoint/flows_endpoint.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,23 +308,24 @@ def update_connection(self, flow_item: FlowItem, connection_item: ConnectionItem
308308
return connection
309309

310310
@api(version="3.3")
311-
def refresh(self, flow_item: FlowItem) -> JobItem:
311+
def refresh(self, flow_item: Union[FlowItem, str]) -> JobItem:
312312
"""
313313
Runs the flow to refresh the data.
314314
315315
REST API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_flow.htm#run_flow_now
316316
317317
Parameters
318318
----------
319-
flow_item: FlowItem
320-
The flow item to refresh.
319+
flow_item: FlowItem | str
320+
The FlowItem or str of the flow id to refresh.
321321
322322
Returns
323323
-------
324324
JobItem
325325
The job item that was created to refresh the flow.
326326
"""
327-
url = f"{self.baseurl}/{flow_item.id}/run"
327+
flow_id = getattr(flow_item, "id", flow_item)
328+
url = f"{self.baseurl}/{flow_id}/run"
328329
empty_req = RequestFactory.Empty.empty_req()
329330
server_response = self.post_request(url, empty_req)
330331
new_job = JobItem.from_response(server_response.content, self.parent_srv.namespace)[0]

test/test_flow.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def test_publish_file_object(self) -> None:
197197
self.assertEqual("default", new_flow.project_name)
198198
self.assertEqual("5de011f8-5aa9-4d5b-b991-f462c8dd6bb7", new_flow.owner_id)
199199

200-
def test_refresh(self):
200+
def test_refresh(self) -> None:
201201
with open(asset(REFRESH_XML), "rb") as f:
202202
response_xml = f.read().decode("utf-8")
203203
with requests_mock.mock() as m:
@@ -215,6 +215,22 @@ def test_refresh(self):
215215
self.assertEqual(refresh_job.flow_run.flow_id, "92967d2d-c7e2-46d0-8847-4802df58f484")
216216
self.assertEqual(format_datetime(refresh_job.flow_run.started_at), "2018-05-22T13:00:29Z")
217217

218+
def test_refresh_id_str(self) -> None:
219+
with open(asset(REFRESH_XML), "rb") as f:
220+
response_xml = f.read().decode("utf-8")
221+
with requests_mock.mock() as m:
222+
m.post(self.baseurl + "/92967d2d-c7e2-46d0-8847-4802df58f484/run", text=response_xml)
223+
refresh_job = self.server.flows.refresh("92967d2d-c7e2-46d0-8847-4802df58f484")
224+
225+
self.assertEqual(refresh_job.id, "d1b2ccd0-6dfa-444a-aee4-723dbd6b7c9d")
226+
self.assertEqual(refresh_job.mode, "Asynchronous")
227+
self.assertEqual(refresh_job.type, "RunFlow")
228+
self.assertEqual(format_datetime(refresh_job.created_at), "2018-05-22T13:00:29Z")
229+
self.assertIsInstance(refresh_job.flow_run, TSC.FlowRunItem)
230+
self.assertEqual(refresh_job.flow_run.id, "e0c3067f-2333-4eee-8028-e0a56ca496f6")
231+
self.assertEqual(refresh_job.flow_run.flow_id, "92967d2d-c7e2-46d0-8847-4802df58f484")
232+
self.assertEqual(format_datetime(refresh_job.flow_run.started_at), "2018-05-22T13:00:29Z")
233+
218234
def test_bad_download_response(self) -> None:
219235
with requests_mock.mock() as m, tempfile.TemporaryDirectory() as td:
220236
m.get(

0 commit comments

Comments
 (0)