Skip to content

Commit

Permalink
[sc-187164] Fix: Invalid page number when querying tableau (#29)
Browse files Browse the repository at this point in the history
Fix: Correctly compute the total number of pages needed to query projects from a Tableau server to avoid invalid page number errors
  • Loading branch information
alexandremgo authored Jun 4, 2024
1 parent 0ac5aed commit 062e944
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [Version 0.2.5](https://github.com/dataiku/dss-plugin-tableau-hyper/releases/tag/v0.2.5) - Feature release - 2024-06-04

- Fix: Correctly compute the total number of pages needed to query projects from a Tableau server to avoid invalid page number errors

## [Version 0.2.4](https://github.com/dataiku/dss-plugin-tableau-hyper/releases/tag/v0.2.4) - Feature release - 2024-05-24

- Chore: Removed usage of `.cache` directory, letting `tempfile` handle the location of the temporary file
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "tableau-hyper-export",
"version": "0.2.4",
"version": "0.2.5",
"meta": {
"label": "Tableau Hyper format",
"description": "Export datasets to Tableau .hyper format.",
Expand Down
48 changes: 36 additions & 12 deletions python-lib/tableau_server_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ def get_project_from_name(server, project_name):
:param project_name: target project name
:return: couple (Boolean{target project exists on server}, project)
"""
page_nb = 1
logger.info(f"Searching for project {project_name}")
pages_in_total = compute_total_pages_for_projects(server)

all_project_items, pag_it = server.projects.get(req_options=tsc.RequestOptions(pagenumber=page_nb))
pages_in_total = (pag_it.total_available // pag_it.page_size) + 1
page_nb = 1

while page_nb <= pages_in_total:
all_project_items, pag_it = server.projects.get(req_options=tsc.RequestOptions(pagenumber=page_nb))
all_project_items, _pag_it = server.projects.get(req_options=tsc.RequestOptions(pagenumber=page_nb))
filtered_projects = list(
filter(lambda x: x.name.encode('utf-8') == project_name, all_project_items)
)
Expand All @@ -44,14 +44,14 @@ def get_full_list_of_projects(server):
:param server:
:return:
"""
page_nb = 1
all_project_items, pag_it = server.projects.get(req_options=tsc.RequestOptions(pagenumber=page_nb))
pages_in_total = (pag_it.total_available // pag_it.page_size) + 1
pages_in_total = compute_total_pages_for_projects(server)

all_projects = set()
page_nb = 1

while page_nb <= pages_in_total:

all_project_items, pag_it = server.projects.get(req_options=tsc.RequestOptions(pagenumber=page_nb))
all_project_items, _pag_it = server.projects.get(req_options=tsc.RequestOptions(pagenumber=page_nb))
project_names = [x.name.encode('utf-8') for x in all_project_items]
for name in project_names:
all_projects.add(name)
Expand All @@ -62,14 +62,17 @@ def get_full_list_of_projects(server):


def get_dict_of_projects_paths(server):
page_nb = 1
all_project_items, pag_it = server.projects.get(req_options=tsc.RequestOptions(pagenumber=page_nb))
pages_in_total = (pag_it.total_available // pag_it.page_size) + 1
"""
Computes a dictionary of all the available projects from a Tableau server
"""
pages_in_total = compute_total_pages_for_projects(server)

all_projects = {}
page_nb = 1

while page_nb <= pages_in_total:

all_project_items, pag_it = server.projects.get(req_options=tsc.RequestOptions(pagenumber=page_nb))
all_project_items, _pag_it = server.projects.get(req_options=tsc.RequestOptions(pagenumber=page_nb))
for all_project_item in all_project_items:
all_projects[all_project_item.id] = {"name": all_project_item.name, "parent": all_project_item.parent_id}
page_nb += 1
Expand Down Expand Up @@ -159,3 +162,24 @@ def setup_ssl(ignore_ssl, ssl_cert_path):
# default variables handled by python requests to validate cert (used by underlying tableauserverclient)
os.environ['REQUESTS_CA_BUNDLE'] = ssl_cert_path
os.environ['CURL_CA_BUNDLE'] = ssl_cert_path


def compute_total_pages_for_projects(server) -> int:
"""
Computes the number of pages necessary to query all the projects available on a Tableau server
:param server: tableau server
:return: Total number of pages
"""
_project_items, pag_it = server.projects.get(
req_options=tsc.RequestOptions(pagenumber=1)
)

partial_page = 1 if pag_it.total_available % pag_it.page_size > 0 else 0
pages_in_total = (pag_it.total_available // pag_it.page_size) + partial_page

logger.info(
f"{pag_it.total_available} projects, divided in {pages_in_total} pages ({partial_page} partial page) with a page size of {pag_it.page_size}"
)

return pages_in_total

0 comments on commit 062e944

Please sign in to comment.