From 0fa709dd46d7d7dce3983c9fcf5f9d052c88a27d Mon Sep 17 00:00:00 2001 From: Jordan Woods <13803242+jorwoods@users.noreply.github.com> Date: Thu, 6 Feb 2025 21:13:11 -0600 Subject: [PATCH] fix: remove vizHeight and vizWidth from ImageRequestOptions Closes #1564 Retrieving a view image does not support vizHeight and vizWidth serverside. Supporting it for images as well was a mistake. --- tableauserverclient/server/request_options.py | 92 ++++++++----------- 1 file changed, 40 insertions(+), 52 deletions(-) diff --git a/tableauserverclient/server/request_options.py b/tableauserverclient/server/request_options.py index c37c0ce42..534b517b8 100644 --- a/tableauserverclient/server/request_options.py +++ b/tableauserverclient/server/request_options.py @@ -268,46 +268,6 @@ def _append_view_filters(self, params) -> None: params[name] = value -class _ImagePDFCommonExportOptions(_DataExportOptions): - def __init__(self, maxage=-1, viz_height=None, viz_width=None): - super().__init__(maxage=maxage) - self.viz_height = viz_height - self.viz_width = viz_width - - @property - def viz_height(self): - return self._viz_height - - @viz_height.setter - @property_is_int(range=(0, sys.maxsize), allowed=(None,)) - def viz_height(self, value): - self._viz_height = value - - @property - def viz_width(self): - return self._viz_width - - @viz_width.setter - @property_is_int(range=(0, sys.maxsize), allowed=(None,)) - def viz_width(self, value): - self._viz_width = value - - def get_query_params(self) -> dict: - params = super().get_query_params() - - # XOR. Either both are None or both are not None. - if (self.viz_height is None) ^ (self.viz_width is None): - raise ValueError("viz_height and viz_width must be specified together") - - if self.viz_height is not None: - params["vizHeight"] = self.viz_height - - if self.viz_width is not None: - params["vizWidth"] = self.viz_width - - return params - - class CSVRequestOptions(_DataExportOptions): """ Options that can be used when exporting a view to CSV. Set the maxage to control the age of the data exported. @@ -338,7 +298,7 @@ class ExcelRequestOptions(_DataExportOptions): extension = "xlsx" -class ImageRequestOptions(_ImagePDFCommonExportOptions): +class ImageRequestOptions(_DataExportOptions): """ Options that can be used when exporting a view to an image. Set the maxage to control the age of the data exported. Filters to the underlying data can be applied using the `vf` and `parameter` methods. @@ -354,13 +314,6 @@ class ImageRequestOptions(_ImagePDFCommonExportOptions): maxage: int, optional The maximum age of the data to export. Shortest possible duration is 1 minute. No upper limit. Default is -1, which means no limit. - - viz_height: int, optional - The height of the viz in pixels. If specified, viz_width must also be specified. - - viz_width: int, optional - The width of the viz in pixels. If specified, viz_height must also be specified. - """ extension = "png" @@ -369,8 +322,10 @@ class ImageRequestOptions(_ImagePDFCommonExportOptions): class Resolution: High = "high" - def __init__(self, imageresolution=None, maxage=-1, viz_height=None, viz_width=None): - super().__init__(maxage=maxage, viz_height=viz_height, viz_width=viz_width) + def __init__(self, imageresolution=None, maxage=-1): + super().__init__( + maxage=maxage, + ) self.image_resolution = imageresolution def get_query_params(self): @@ -380,7 +335,7 @@ def get_query_params(self): return params -class PDFRequestOptions(_ImagePDFCommonExportOptions): +class PDFRequestOptions(_DataExportOptions): """ Options that can be used when exporting a view to PDF. Set the maxage to control the age of the data exported. Filters to the underlying data can be applied using the `vf` and `parameter` methods. @@ -425,12 +380,45 @@ class Orientation: Landscape = "landscape" def __init__(self, page_type=None, orientation=None, maxage=-1, viz_height=None, viz_width=None): - super().__init__(maxage=maxage, viz_height=viz_height, viz_width=viz_width) + super().__init__( + maxage=maxage, + ) self.page_type = page_type self.orientation = orientation + self.viz_height = viz_height + self.viz_width = viz_width + + @property + def viz_height(self): + return self._viz_height + + @viz_height.setter + @property_is_int(range=(0, sys.maxsize), allowed=(None,)) + def viz_height(self, value): + self._viz_height = value + + @property + def viz_width(self): + return self._viz_width + + @viz_width.setter + @property_is_int(range=(0, sys.maxsize), allowed=(None,)) + def viz_width(self, value): + self._viz_width = value def get_query_params(self) -> dict: params = super().get_query_params() + + # XOR. Either both are None or both are not None. + if (self.viz_height is None) ^ (self.viz_width is None): + raise ValueError("viz_height and viz_width must be specified together") + + if self.viz_height is not None: + params["vizHeight"] = self.viz_height + + if self.viz_width is not None: + params["vizWidth"] = self.viz_width + if self.page_type: params["type"] = self.page_type