tableau / server-client-python

A Python library for the Tableau Server REST API
https://tableau.github.io/server-client-python/
MIT License
656 stars 420 forks source link

Filter parameters in live connection are ignored during PDF or CSV generation #1438

Open mohit-rana85 opened 1 month ago

mohit-rana85 commented 1 month ago

Describe the bug Our workbooks contain data sources in extract mode for performance optimization. However, some data sources that are required for annotating the data need to remain in live connection mode to enhance the user experience. When we generate a pdf or csv from a view using the TSC package, all parameters in the extract are considered by the code, but the filters specific to selecting data in the live connection are ignored.

Versions Details of your environment, including:

To Reproduce Steps to reproduce the behavior. Please include a code snippet where possible. We have a workbook with Impala connection (Extract) and oracle connection (Live connection).

Python code:

import tableauserverclient as TSC

SERVER_URL = 'your_server_url'
TOKEN_NAME = 'your_token_name'
TOKEN_VALUE = 'your_token_value'
SITE_NAME = 'your_site_name'
VIEW_NAME = 'your_view_name'
WORKBOOK_ID= 'your_workbook_id'

# initiate server connection 
server = TSC.Server(SERVER_URL, use_server_version=True)

# Use Personal Access Token for authentication
tableau_auth = TSC.PersonalAccessTokenAuth(token_name=TOKEN_NAME, personal_access_token=TOKEN_VALUE,
                                                site_id=SITE_NAME)
server.add_http_options({'verify': False})
server.version = '3.21'
server.auth.sign_in(tableau_auth)

# get workbook object 
workbook = server.workbooks.get_by_id(WORKBOOK_ID)

# populate view and specify filter parameters on the worksheet
server.workbooks.populate_views(workbook)
# Find the specific view by name
 view = next((v for v in workbook.views if v.name == VIEW_NAME), None)
req = TSC.PDFRequestOptions(maxage=-1, page_type='unspecified', orientation='landscape', viz_width=1200,
                                     viz_height=1000)
req.vf('country', 'Germany')  # parameter in extract
req.vf('company', 'abc')  # parameter in extract
req.vf('selected', 1)   # parameter in live connection

# populate pdf file
server.views.populate_pdf(view, req_options=req)

# write pdf file
output_file = "test.pdf"
 with open(output_file, 'wb') as file:
         file.write(view.pdf)

Results What are the results or error messages received? The PDF generated with the above code produces a report that ignores the "selected" parameter. The expected behavior is that the PDF should be generated considering all specified parameters, including those associated with the live connection.

NOTE: Be careful not to post user names, passwords, auth tokens or any other private or sensitive information.

jorwoods commented 1 month ago

.vf is for filters in the view, e.g. quick filters. Set parameters via .parameter.

mohit-rana85 commented 1 month ago

Hi @jorwoods, Thanks for the hint. I tried using the .parameter method, but it didn't change the result.

mohit-rana85 commented 1 month ago

Hi @jorwoods, I tested the parameter method by providing some arbitrary value for the filter that should have resulted in empty PDF values, as it does with other filters on parameters present in the extract. However, the result remained exactly the same. Somehow, the filter for the parameter present in the live connection is completely ignored.