Skip to content

Commit

Permalink
Streamlined create_mode to create/overwrite
Browse files Browse the repository at this point in the history
Removed logic checking if data source already exists and simply set it to create_mode = Overwrite. If data source doesn't exist, it will be created using this setting so the resulting publish logic should be the same as intended.
  • Loading branch information
harrywatts125 committed Feb 24, 2022
1 parent 2cdb0c1 commit ea06ed6
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions hyperleaup/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, tableau_server_url: str,
self.datasource_luid = None
self.hyper_file_path = hyper_file_path

def publish(self, creation_mode='CreateNew'):
def publish(self, creation_mode = 'Overwrite'):
"""Publishes a Hyper File to a Tableau Server"""

# Ensure that the Hyper File exists
Expand Down Expand Up @@ -75,8 +75,8 @@ def publish(self, creation_mode='CreateNew'):
f'on the Tableau server.')

# Next, check if the datasource already exists and needs to be overwritten
create_mode = TSC.Server.PublishMode.CreateNew
if creation_mode.upper() == 'CREATENEW':
create_mode = TSC.Server.PublishMode.Overwrite
if creation_mode.upper() == 'OVERWRITE':

# Search for the datasource under project name
req_options = TSC.RequestOptions()
Expand All @@ -87,14 +87,11 @@ def publish(self, creation_mode='CreateNew'):
TSC.RequestOptions.Operator.Equals,
self.datasource_name))
datasources, pagination = server.datasources.get(req_options=req_options)
for datasource in datasources:
# the datasource already exists, overwrite
if datasource.name == self.datasource_name:
logging.info(f'Overwriting existing datasource named "{self.datasource_name}".')
create_mode = TSC.Server.PublishMode.Overwrite
break

elif creation_mode.upper() == 'APPEND':
create_mode = TSC.Server.PublishMode.Append


else:
raise ValueError(f'Invalid "creation_mode" : {creation_mode}')

Expand Down

0 comments on commit ea06ed6

Please sign in to comment.