From 3275925df6f1284d21b3a9a3137a2a583b32708b Mon Sep 17 00:00:00 2001 From: Jordan Woods Date: Fri, 10 Jan 2025 03:33:25 -0600 Subject: [PATCH] Jorwoods/datasource refresh hotfix (#1554) * hotfix: Datasource refresh expects empty requests. Closes #1553 --------- Co-authored-by: Jordan Woods <13803242+jorwoods@users.noreply.github.com> --- .../server/endpoint/datasources_endpoint.py | 3 ++- test/test_datasource.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tableauserverclient/server/endpoint/datasources_endpoint.py b/tableauserverclient/server/endpoint/datasources_endpoint.py index 1f00af57..5a48f3c9 100644 --- a/tableauserverclient/server/endpoint/datasources_endpoint.py +++ b/tableauserverclient/server/endpoint/datasources_endpoint.py @@ -190,7 +190,8 @@ def update_connection( def refresh(self, datasource_item: DatasourceItem, incremental: bool = False) -> JobItem: id_ = getattr(datasource_item, "id", datasource_item) url = f"{self.baseurl}/{id_}/refresh" - refresh_req = RequestFactory.Task.refresh_req(incremental) + # refresh_req = RequestFactory.Task.refresh_req(incremental) + refresh_req = RequestFactory.Empty.empty_req() server_response = self.post_request(url, refresh_req) new_job = JobItem.from_response(server_response.content, self.parent_srv.namespace)[0] return new_job diff --git a/test/test_datasource.py b/test/test_datasource.py index e8a95722..b7e7e272 100644 --- a/test/test_datasource.py +++ b/test/test_datasource.py @@ -366,6 +366,25 @@ def test_refresh_object(self) -> None: # We only check the `id`; remaining fields are already tested in `test_refresh_id` self.assertEqual("7c3d599e-949f-44c3-94a1-f30ba85757e4", new_job.id) + def test_datasource_refresh_request_empty(self) -> None: + self.server.version = "2.8" + self.baseurl = self.server.datasources.baseurl + item = TSC.DatasourceItem("") + item._id = "1234" + text = read_xml_asset(REFRESH_XML) + + def match_request_body(request): + try: + root = fromstring(request.body) + assert root.tag == "tsRequest" + assert len(root) == 0 + return True + except Exception: + return False + + with requests_mock.mock() as m: + m.post(f"{self.baseurl}/1234/refresh", text=text, additional_matcher=match_request_body) + def test_update_hyper_data_datasource_object(self) -> None: """Calling `update_hyper_data` with a `DatasourceItem` should update that datasource""" self.server.version = "3.13"