From 6d31b73b6fc51ec5c36096b5c1b151bebf44e3e0 Mon Sep 17 00:00:00 2001 From: Ranjith Guggilla Date: Sat, 21 Nov 2026 21:03:01 -0600 Subject: [PATCH 1/2] fix: send encryptExtracts when publishing a workbook The publish workbook method documents an optional encryptExtracts attribute, and TSC already sends it for data sources. A workbook had no way to set it, so publish could not choose extract encryption. --- tableauserverclient/models/workbook_item.py | 10 +++++++++- tableauserverclient/server/request_factory.py | 2 ++ test/test_workbook.py | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/tableauserverclient/models/workbook_item.py b/tableauserverclient/models/workbook_item.py index 75ca0034e..9f4b1ec40 100644 --- a/tableauserverclient/models/workbook_item.py +++ b/tableauserverclient/models/workbook_item.py @@ -61,7 +61,10 @@ class as arguments. The workbook item specifies the project. User-defined description of the workbook. encrypt_extracts : bool | None - Indicates whether extracts are encrypted. + Set this before publishing to send ``encryptExtracts``. ``True`` encrypts + the workbook's extracts and ``False`` leaves them unencrypted. ``None`` + omits the attribute, which is also what a workbook parsed from the + server uses when the response does not include it. has_extracts : bool | None Indicates whether the workbook has extracts. @@ -357,6 +360,11 @@ def location(self) -> LocationItem | None: def encrypt_extracts(self) -> bool | None: return self._encrypt_extracts + @encrypt_extracts.setter + @property_is_boolean + def encrypt_extracts(self, value: bool) -> None: + self._encrypt_extracts = value + @property def default_view_id(self) -> str | None: return self._default_view_id diff --git a/tableauserverclient/server/request_factory.py b/tableauserverclient/server/request_factory.py index 517a26956..f416f7312 100644 --- a/tableauserverclient/server/request_factory.py +++ b/tableauserverclient/server/request_factory.py @@ -1070,6 +1070,8 @@ def _generate_xml( workbook_element.attrib["name"] = workbook_item.name if workbook_item.show_tabs: workbook_element.attrib["showTabs"] = str(workbook_item.show_tabs).lower() + if workbook_item.encrypt_extracts is not None: + workbook_element.attrib["encryptExtracts"] = str(workbook_item.encrypt_extracts).lower() project_element = ET.SubElement(workbook_element, "project") project_element.attrib["id"] = str(workbook_item.project_id) diff --git a/test/test_workbook.py b/test/test_workbook.py index c0965f121..109ab2ebc 100644 --- a/test/test_workbook.py +++ b/test/test_workbook.py @@ -884,6 +884,20 @@ def test_publish_file_object_of_unknown_type_raises_exception(server: TSC.Server server.workbooks.publish(new_workbook, file_object, server.PublishMode.CreateNew) +def test_publish_sends_encrypt_extracts_when_set(server: TSC.Server) -> None: + new_workbook = TSC.WorkbookItem(name="Sample", show_tabs=False, project_id="ee8c6e70-43b6-11e6-af4f-f7b0d8e20760") + omitted = RequestFactory.Workbook._generate_xml(new_workbook) + assert "encryptExtracts" not in fromstring(omitted).find("workbook").attrib + + new_workbook.encrypt_extracts = True + encrypted = RequestFactory.Workbook._generate_xml(new_workbook) + assert fromstring(encrypted).find("workbook").get("encryptExtracts") == "true" + + new_workbook.encrypt_extracts = False + plain = RequestFactory.Workbook._generate_xml(new_workbook) + assert fromstring(plain).find("workbook").get("encryptExtracts") == "false" + + def test_publish_multi_connection(server: TSC.Server) -> None: new_workbook = TSC.WorkbookItem(name="Sample", show_tabs=False, project_id="ee8c6e70-43b6-11e6-af4f-f7b0d8e20760") connection1 = TSC.ConnectionItem() From f70f830246b137cdd495576b87547b65df7e2cbd Mon Sep 17 00:00:00 2001 From: Ranjith Guggilla Date: Tue, 24 Nov 2026 18:44:31 -0600 Subject: [PATCH 2/2] fix: send encryptExtracts only when the caller assigns it A workbook fetched from the server already has encryptExtracts parsed into a bool. Publishing that item sent the value on, and a destination site that enforces or disables encryption rejects the other value. Publish now sends the attribute only after the property is assigned, and assigning None omits it again. --- tableauserverclient/models/workbook_item.py | 18 ++++++++----- tableauserverclient/server/request_factory.py | 2 +- test/test_workbook.py | 25 +++++++++++++++++++ 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/tableauserverclient/models/workbook_item.py b/tableauserverclient/models/workbook_item.py index 9f4b1ec40..872b70926 100644 --- a/tableauserverclient/models/workbook_item.py +++ b/tableauserverclient/models/workbook_item.py @@ -61,10 +61,13 @@ class as arguments. The workbook item specifies the project. User-defined description of the workbook. encrypt_extracts : bool | None - Set this before publishing to send ``encryptExtracts``. ``True`` encrypts - the workbook's extracts and ``False`` leaves them unencrypted. ``None`` - omits the attribute, which is also what a workbook parsed from the - server uses when the response does not include it. + Assign this before publishing to send ``encryptExtracts``. ``True`` + encrypts the workbook's extracts and ``False`` leaves them unencrypted. + ``None`` omits the attribute. A value read from the server is kept on + the item but is not sent on publish until this property is assigned. + Assign ``None`` to omit it again after a previous assignment. The + server rejects ``false`` on a site that enforces encryption (409037) + and ``true`` on a site where encryption is disabled (409036). has_extracts : bool | None Indicates whether the workbook has extracts. @@ -172,6 +175,7 @@ def __init__( self._owner: UserItem | None = None self._location: LocationItem | None = None self._encrypt_extracts: bool | None = None + self._encrypt_extracts_assigned = False self._default_view_id: str | None = None self._share_description: str | None = None self._last_published_at: datetime.datetime | None = None @@ -361,9 +365,11 @@ def encrypt_extracts(self) -> bool | None: return self._encrypt_extracts @encrypt_extracts.setter - @property_is_boolean - def encrypt_extracts(self, value: bool) -> None: + def encrypt_extracts(self, value: bool | None) -> None: + if value is not None and not isinstance(value, bool): + raise ValueError("Boolean expected for encrypt_extracts flag.") self._encrypt_extracts = value + self._encrypt_extracts_assigned = True @property def default_view_id(self) -> str | None: diff --git a/tableauserverclient/server/request_factory.py b/tableauserverclient/server/request_factory.py index f416f7312..b209beb5d 100644 --- a/tableauserverclient/server/request_factory.py +++ b/tableauserverclient/server/request_factory.py @@ -1070,7 +1070,7 @@ def _generate_xml( workbook_element.attrib["name"] = workbook_item.name if workbook_item.show_tabs: workbook_element.attrib["showTabs"] = str(workbook_item.show_tabs).lower() - if workbook_item.encrypt_extracts is not None: + if workbook_item._encrypt_extracts_assigned and workbook_item.encrypt_extracts is not None: workbook_element.attrib["encryptExtracts"] = str(workbook_item.encrypt_extracts).lower() project_element = ET.SubElement(workbook_element, "project") project_element.attrib["id"] = str(workbook_item.project_id) diff --git a/test/test_workbook.py b/test/test_workbook.py index 109ab2ebc..b98fc9b20 100644 --- a/test/test_workbook.py +++ b/test/test_workbook.py @@ -897,6 +897,31 @@ def test_publish_sends_encrypt_extracts_when_set(server: TSC.Server) -> None: plain = RequestFactory.Workbook._generate_xml(new_workbook) assert fromstring(plain).find("workbook").get("encryptExtracts") == "false" + new_workbook.encrypt_extracts = None + cleared = RequestFactory.Workbook._generate_xml(new_workbook) + assert "encryptExtracts" not in fromstring(cleared).find("workbook").attrib + + with pytest.raises(ValueError): + new_workbook.encrypt_extracts = "true" # type: ignore[assignment] + + +def test_publish_does_not_send_encrypt_extracts_read_from_the_server(server: TSC.Server) -> None: + response = """ + + + + + + """ + fetched = TSC.WorkbookItem.from_response(response, server.namespace)[0] + assert fetched.encrypt_extracts is True + omitted = RequestFactory.Workbook._generate_xml(fetched) + assert "encryptExtracts" not in fromstring(omitted).find("workbook").attrib + + fetched.encrypt_extracts = False + chosen = RequestFactory.Workbook._generate_xml(fetched) + assert fromstring(chosen).find("workbook").get("encryptExtracts") == "false" + def test_publish_multi_connection(server: TSC.Server) -> None: new_workbook = TSC.WorkbookItem(name="Sample", show_tabs=False, project_id="ee8c6e70-43b6-11e6-af4f-f7b0d8e20760")