Skip to content

Commit e9d4860

Browse files
jacalataclaude
andauthored
feat: add vizWidth/vizHeight to PDF export for views and workbooks (#1795)
* feat: add vizWidth/vizHeight to PDFRequestOptions Fixes #1102 - PDFRequestOptions already inherited viz_width/viz_height from _ImagePDFCommonExportOptions (shared with ImageRequestOptions), which serialises them as vizWidth/vizHeight query params - Added version guard in views.populate_pdf: raises UnsupportedAttributeError when viz_height or viz_width are used below API 3.26 - Added tests for the new version guard, the happy path (API 3.26+), unit- level query-param serialisation, and the existing XOR validation - Removed stray bare literal '44' from test_request_option.py Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: remove incorrect version gate on vizWidth/vizHeight for PDF export The REST API docs claimed vizHeight/vizWidth required API 3.26 and were Cloud-only, but server-side code shows these params have been accepted unconditionally since at least 2021.4 with no platform distinction. Remove the 3.26 guard; the endpoint's own minimum version is sufficient. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 4849074 commit e9d4860

4 files changed

Lines changed: 45 additions & 12 deletions

File tree

tableauserverclient/server/endpoint/views_endpoint.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ def populate_pdf(self, view_item: ViewItem, req_options: "PDFRequestOptions | No
204204
205205
req_options: PDFRequestOptions | None, default None
206206
Optional request options for the request. These options can include
207-
parameters such as orientation and paper size.
207+
parameters such as orientation, paper size, and viz dimensions
208+
(viz_width and viz_height).
208209
209210
Returns
210211
-------

tableauserverclient/server/endpoint/workbooks_endpoint.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -623,12 +623,10 @@ def populate_pdf(self, workbook_item: WorkbookItem, req_options: "PDFRequestOpti
623623
def pdf_fetcher() -> bytes:
624624
return self._get_wb_pdf(workbook_item, req_options)
625625

626-
if not self.parent_srv.check_at_least_version("3.23") and req_options is not None:
627-
if req_options.view_filters or req_options.view_parameters:
628-
raise UnsupportedAttributeError("view_filters and view_parameters are only supported in 3.23+")
629-
630-
if req_options.viz_height or req_options.viz_width:
631-
raise UnsupportedAttributeError("viz_height and viz_width are only supported in 3.23+")
626+
if req_options is not None:
627+
if not self.parent_srv.check_at_least_version("3.23"):
628+
if req_options.view_filters or req_options.view_parameters:
629+
raise UnsupportedAttributeError("view_filters and view_parameters are only supported in 3.23+")
632630

633631
workbook_item._set_pdf(pdf_fetcher)
634632
logger.info(f"Populated pdf for workbook (ID: {workbook_item.id})")

test/test_request_option.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,6 @@ def test_queryset_endpoint_pagesize_filter(server: TSC.Server, page_size: int) -
380380
_ = list(queryset)
381381

382382

383-
44
384-
385-
386383
@pytest.mark.parametrize("page_size", [1, 10, 100, 1_000])
387384
def test_queryset_pagesize_filter(server: TSC.Server, page_size: int) -> None:
388385
with requests_mock.mock() as m:
@@ -441,3 +438,41 @@ def test_queryset_field_all(server: TSC.Server) -> None:
441438
fields = history.qs.get("fields", [""])[0]
442439

443440
assert fields == "_all_"
441+
442+
443+
def test_pdf_viz_dimensions_query_params() -> None:
444+
opts = TSC.PDFRequestOptions(viz_width=1920, viz_height=1080)
445+
params = opts.get_query_params()
446+
assert params["vizWidth"] == 1920
447+
assert params["vizHeight"] == 1080
448+
449+
450+
def test_pdf_viz_dimensions_only_one_raises() -> None:
451+
opts = TSC.PDFRequestOptions(viz_width=1920)
452+
with pytest.raises(ValueError):
453+
opts.get_query_params()
454+
455+
opts2 = TSC.PDFRequestOptions(viz_height=1080)
456+
with pytest.raises(ValueError):
457+
opts2.get_query_params()
458+
459+
460+
def test_pdf_viz_dimensions_none_by_default() -> None:
461+
opts = TSC.PDFRequestOptions()
462+
params = opts.get_query_params()
463+
assert "vizWidth" not in params
464+
assert "vizHeight" not in params
465+
466+
467+
def test_pdf_viz_dimensions_via_request(server: TSC.Server) -> None:
468+
with requests_mock.mock() as m:
469+
m.get(requests_mock.ANY)
470+
url = server.views.baseurl + "/abc/pdf"
471+
opts = TSC.PDFRequestOptions(viz_width=800, viz_height=600)
472+
473+
resp = server.views.get_request(url, request_object=opts)
474+
query_string = parse_qs(resp.request.query)
475+
assert "vizwidth" in query_string
476+
assert ["800"] == query_string["vizwidth"]
477+
assert "vizheight" in query_string
478+
assert ["600"] == query_string["vizheight"]

test/test_view.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,7 @@ def test_filter_excel(server: TSC.Server) -> None:
427427
assert response == excel_file
428428

429429

430-
def test_pdf_height(server: TSC.Server) -> None:
431-
server.version = "3.8"
430+
def test_pdf_viz_dimensions(server: TSC.Server) -> None:
432431
response = POPULATE_PDF.read_bytes()
433432
with requests_mock.mock() as m:
434433
m.get(

0 commit comments

Comments
 (0)