Skip to content

Commit 4d1ed53

Browse files
committed
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
1 parent e648cd4 commit 4d1ed53

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

tableauserverclient/server/request_factory.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ def _generate_xml(self, datasource_item: DatasourceItem, connection_credentials=
184184
project_element = ET.SubElement(datasource_element, "project")
185185
project_element.attrib["id"] = datasource_item.project_id
186186

187+
if datasource_item.description is not None:
188+
datasource_element.attrib["description"] = datasource_item.description
189+
187190
if connection_credentials is not None and connections is not None:
188191
raise RuntimeError("You cannot set both `connections` and `connection_credentials`")
189192

@@ -196,7 +199,7 @@ def _generate_xml(self, datasource_item: DatasourceItem, connection_credentials=
196199
_add_connections_element(connections_element, connection)
197200
return ET.tostring(xml_request)
198201

199-
def update_req(self, datasource_item):
202+
def update_req(self, datasource_item: DatasourceItem) -> bytes:
200203
xml_request = ET.Element("tsRequest")
201204
datasource_element = ET.SubElement(xml_request, "datasource")
202205
if datasource_item.name:
@@ -219,6 +222,8 @@ def update_req(self, datasource_item):
219222
datasource_element.attrib["certificationNote"] = str(datasource_item.certification_note)
220223
if datasource_item.encrypt_extracts is not None:
221224
datasource_element.attrib["encryptExtracts"] = str(datasource_item.encrypt_extracts).lower()
225+
if datasource_item.description is not None:
226+
datasource_element.attrib["description"] = datasource_item.description
222227

223228
return ET.tostring(xml_request)
224229

test/test_datasource.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,3 +850,23 @@ def test_get_datasource_all_fields(server) -> None:
850850
assert datasources[0].owner.last_login == parse_datetime("2025-02-04T06:39:20Z")
851851
assert datasources[0].owner.name == "bob@example.com"
852852
assert datasources[0].owner.site_role == "SiteAdministratorCreator"
853+
854+
855+
def test_update_description(server: TSC.Server) -> None:
856+
response_xml = UPDATE_XML.read_text()
857+
with requests_mock.mock() as m:
858+
m.put(server.datasources.baseurl + "/9dbd2263-16b5-46e1-9c43-a76bb8ab65fb", text=response_xml)
859+
single_datasource = TSC.DatasourceItem("1d0304cd-3796-429f-b815-7258370b9b74", "Sample datasource")
860+
single_datasource.owner_id = "dd2239f6-ddf1-4107-981a-4cf94e415794"
861+
single_datasource._content_url = "Sampledatasource"
862+
single_datasource._id = "9dbd2263-16b5-46e1-9c43-a76bb8ab65fb"
863+
single_datasource.certified = True
864+
single_datasource.certification_note = "Warning, here be dragons."
865+
single_datasource.description = "Sample description"
866+
_ = server.datasources.update(single_datasource)
867+
868+
history = m.request_history[0]
869+
body = fromstring(history.body)
870+
ds_elem = body.find(".//datasource")
871+
assert ds_elem is not None
872+
assert ds_elem.attrib["description"] == "Sample description"

0 commit comments

Comments
 (0)