From c0f5c94b728c23446992b6940ced258b7e7d0cf8 Mon Sep 17 00:00:00 2001 From: Jordan Woods <13803242+jorwoods@users.noreply.github.com> Date: Wed, 5 Nov 2025 21:17:27 -0600 Subject: [PATCH] fix: datasource description update and publish Publish and update datasource were missing adding in the description to the XML. This PR adds it in. Co-authored-by: raccoooonz --- tableauserverclient/server/request_factory.py | 7 ++++++- test/test_datasource.py | 20 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/tableauserverclient/server/request_factory.py b/tableauserverclient/server/request_factory.py index 877a18c39..05c4cf1dd 100644 --- a/tableauserverclient/server/request_factory.py +++ b/tableauserverclient/server/request_factory.py @@ -184,6 +184,9 @@ def _generate_xml(self, datasource_item: DatasourceItem, connection_credentials= project_element = ET.SubElement(datasource_element, "project") project_element.attrib["id"] = datasource_item.project_id + if datasource_item.description is not None: + datasource_element.attrib["description"] = datasource_item.description + if connection_credentials is not None and connections is not None: raise RuntimeError("You cannot set both `connections` and `connection_credentials`") @@ -196,7 +199,7 @@ def _generate_xml(self, datasource_item: DatasourceItem, connection_credentials= _add_connections_element(connections_element, connection) return ET.tostring(xml_request) - def update_req(self, datasource_item): + def update_req(self, datasource_item: DatasourceItem) -> bytes: xml_request = ET.Element("tsRequest") datasource_element = ET.SubElement(xml_request, "datasource") if datasource_item.name: @@ -219,6 +222,8 @@ def update_req(self, datasource_item): datasource_element.attrib["certificationNote"] = str(datasource_item.certification_note) if datasource_item.encrypt_extracts is not None: datasource_element.attrib["encryptExtracts"] = str(datasource_item.encrypt_extracts).lower() + if datasource_item.description is not None: + datasource_element.attrib["description"] = datasource_item.description return ET.tostring(xml_request) diff --git a/test/test_datasource.py b/test/test_datasource.py index e9635874d..e57328a82 100644 --- a/test/test_datasource.py +++ b/test/test_datasource.py @@ -850,3 +850,23 @@ def test_get_datasource_all_fields(server) -> None: assert datasources[0].owner.last_login == parse_datetime("2025-02-04T06:39:20Z") assert datasources[0].owner.name == "bob@example.com" assert datasources[0].owner.site_role == "SiteAdministratorCreator" + + +def test_update_description(server: TSC.Server) -> None: + response_xml = UPDATE_XML.read_text() + with requests_mock.mock() as m: + m.put(server.datasources.baseurl + "/9dbd2263-16b5-46e1-9c43-a76bb8ab65fb", text=response_xml) + single_datasource = TSC.DatasourceItem("1d0304cd-3796-429f-b815-7258370b9b74", "Sample datasource") + single_datasource.owner_id = "dd2239f6-ddf1-4107-981a-4cf94e415794" + single_datasource._content_url = "Sampledatasource" + single_datasource._id = "9dbd2263-16b5-46e1-9c43-a76bb8ab65fb" + single_datasource.certified = True + single_datasource.certification_note = "Warning, here be dragons." + single_datasource.description = "Sample description" + _ = server.datasources.update(single_datasource) + + history = m.request_history[0] + body = fromstring(history.body) + ds_elem = body.find(".//datasource") + assert ds_elem is not None + assert ds_elem.attrib["description"] == "Sample description"