Skip to content

server.views.populate_image uses a cached image, with no way to clear the cache #568

@kylemcleland-zz

Description

@kylemcleland-zz

I have a series of dashboards with a live SQL connection. The workflow for these dashboards is to run a nightly refresh of the underlying data table, take a screenshot of the dashboard, and email it out to users.

The issue is that after refreshing the SQL connection, server.views.populate_image returns an image of the dashboard from before it is refreshed. (e.g., if I have data for 1/1/2020, truncate that table overnight, insert data for 1/2/2020, then use views.populate_image, it will still show 1/1/2020 data, even though that data is truncated from the underlying data table as Tableau is caching the image of the dashboard).

Here is a snippet of the offending code:

import logging
import tableauserverclient as TSC

workbook_name = "name of workbook containing view"
view_name = "view to print"
report_filter = "dashboard filter value"
filter_name = "dashboard filter name"
report_export_file_name = "file path + file name of image to be generated" 
tableau_auth = [censored]

with server.auth.sign_in_with_personal_access_token(tableau_auth):
    all_workbooks = TSC.Pager(server.workbooks.get)
    workbook = [
        wb
        for wb in all_workbooks
        if wb.name == workbook_name and wb.project_name == workbook_project
    ][0]
    logging.info(f"Found workbook: {workbook_name}")

    # request views from workbook and find first matching view
    server.workbooks.populate_views(workbook)
    view = [v for v in workbook.views if v.name == view_name][0]
    logging.info(f"Downloaded view to memory: {view_name}")

    # request image of view and download it locally
    # maxage = max age of image cached in minutes
    # shortest interval that you can use is one minute
    image_req_option = TSC.ImageRequestOptions(maxage=1)
    if report_filter:
        image_req_option.vf(filter_name, report_filter)

    server.views.populate_image(view, image_req_option)

    # save file
    with open(report_export_file_name, "wb") as view_png:
        view_png.write(view.image)
    logging.info(f"Saved view to {report_export_file_name}")

What I've tried:

Setting maxage to 1 minute, doesn't seem to work as intended, as even running this script >1 minutes after the SQL update sometimes shows a cached view.

Using workbooks.refresh method. Doesn't work as this seems to be expecting a data extract, not live SQL connection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedA user needs help, may be a mistake, a bug or a feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions