server-client-python icon indicating copy to clipboard operation
server-client-python copied to clipboard

server.views.populate_image renders stale image despite usage of maxage param

Open RobbertvK opened this issue 2 years ago • 0 comments

Describe the bug When rendering an image for dashboards that use parameters, the received image is always a stale one. The parameters are sent in using a view filter. The parameters work since the data shown on the dashboard corresponds with the parameters sent in the request. The option 'maxage' is set in the ImageRequestOptions object and sent with the request together with the imageresolution param. The image rendered is in the highest quality so this indicates that the ImageRequestOptions are received properly.

We have even included a parameter named 'cachebuster' in the dashboards. This parameter was added to make sure the request for the view is alway unique (found this possible solution on one of the forum posts). The value is sent in as a view filter in the request.

Versions Details of your environment, including:

  • Tableau Server version: 2022.1 / API version 3.15
  • Python version: 3.9
  • TSC library version: 0.25 ("full-revisionid": "e4fbe41560fbd2314c9c7b8b8a169164dd15185f")

To Reproduce Create dashboard that uses parameters to control the view. Render images using server.views.populate_image

`import json import requests import time from requests.auth import HTTPBasicAuth import tableauserverclient as TSC

dashboards = { "Smulpaap": { "workbook_id": "workbook_id", "views": [ { "filename": "image_name.png", "id": "view_id", "filters": [ {"field": "kies locatie key en naam", "value": 1684}, {"field": "kies datum", "value": <current_date>}, ], }, ], }, }

tableau_auth = TSC.TableauAuth(credentials["username"], credentials["password"]) server = TSC.Server("https://server_url", use_server_version=True)

with server.auth.sign_in(tableau_auth) as auth:

for dashboard_item in dashboards.values():

    workbook = server.workbooks.get_by_id(dashboard_item["workbook_id"])

    for view_setting in dashboard_item["views"]:

        image_req_option = TSC.ImageRequestOptions(
            imageresolution=TSC.ImageRequestOptions.Resolution.High, maxage=1
        )

        # add cachebuster filter by default, this sends in a unique guid for the parameter 'cachebuster'
        image_req_option.vf(f"Parameters.cachebuster", <unique_guid>)

        # iterate over the defined filters and set the desired values in the view filter
        if len(view_setting["filters"]) > 0:
            for filter in view_setting["filters"]:
                image_req_option.vf(f"Parameters.{filter['field']}", filter["value"])

        view = server.views.get_by_id(view_setting["id"])
        server.views.populate_image(view_item=view, req_options=image_req_option)

        # store image in aws s3 bucket
        client.put_object(
            Body=view.image,
            Bucket=get_env("imageBucket"),
            Key=filename,
            ContentType="image/png",
            CacheControl="no-cache",
        )`

Results No errors are received but the image stored is a stale one. It never gets refreshed although the dashboard itself is refreshed every 15 minutes.

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

RobbertvK avatar May 22 '23 08:05 RobbertvK