document-api-python icon indicating copy to clipboard operation
document-api-python copied to clipboard

Replace Datasource

Open benlower opened this issue 9 years ago • 18 comments

(via beta feedback)

Replace data source -- we have QA and prod data sources and it would be good to be able to change the data source a worksheet uses programmatically

benlower avatar Jun 29 '16 00:06 benlower

This is significantly non-trivial.

graysonarts avatar Jun 29 '16 00:06 graysonarts

do we need a "SNT" label for items like this then? :)

benlower avatar Jun 29 '16 00:06 benlower

So wait, it's not a matter of using a conditional on the datasource? I couldn't just modify the below example to change the server name and save the workbook whenever the script is run?


from tableaudocumentapi import Workbook

sourceWB = Workbook('WorkbookToUpdate.twb')

sourceWB.datasources[0].connections[0].server = "MY-NEW-SERVER"
sourceWB.datasources[0].connections[0].dbname = "NEW-DATABASE"
sourceWB.datasources[0].connections[0].username = "benl"

sourceWB.save()

jessebikman avatar Nov 23 '16 04:11 jessebikman

@jessebikman it depends on what the original ask meant to cover for 'Replace Data Source' -- Tableau Desktop has a feature by that name that re-targets all worksheets (including calculations and table calcs) to use the new data source (which may have slightly different properties, like comments on fields).

That's 'SNT'

Just changing the connection information ('sql-dev' to 'sql-prod') is pretty easy, and as you point out, possible today.

t8y8 avatar Nov 28 '16 21:11 t8y8

Oh yes, the feature named that! Ok - thanks for making that more clear. Obvious in hindsight now.

jessebikman avatar Nov 28 '16 23:11 jessebikman

I've run the sample code to modify and save a workbook. I can change the Server name, the Database name, the User name, and the Port, but there does not seem to be any way to change the database table. Hardly seems useful without that. Am I missing something?

ebolz avatar Nov 30 '16 17:11 ebolz

@ebolz please open a new issue with a quick example.

Right now the connection object doesn't expose table name (not all connection types have table) but it would be easy to add!

t8y8 avatar Nov 30 '16 19:11 t8y8

What I'd like is a merge option. if you add a datasource or sheet+datasource, if datasource with same connection details exists, add all customizations and calculated fields from new source to existing. log report for merge conflicts where there are name collisions, etc...

scenario (assumes you know what logshark is or will go look it up now):

  1. logshark makes standard 'canned' twb files
  2. individual cases cause me to make dashboards I'd love to use in future logshark twb files for new log sets
  3. currently I have to copy/paste those dashboards manually and manually replace datasource for pasted dashboard to use new logshark twb's datasource
  4. preference would be to run a script of my design that takes twb (better...tbm!) and a. adds the flippin sweet twb sheets to the new logshark output twb files b. merges the connections so that the workbook still only has one connection for vanilla logshark sheets and my own added sheets with all their lovely aliases and calcs included for all sheets

mattdotgreenlake avatar Dec 09 '16 15:12 mattdotgreenlake

  • 2 votes for this enhancement request from Tableau Elite Customers. I will be happy to provide more information internally. Thank you!

Naiana-Tableau avatar Jan 26 '17 23:01 Naiana-Tableau

In this code: sourceWB.datasources[0].connections[0].server = "MY-NEW-SERVER" sourceWB.datasources[0].connections[0].dbname = "NEW-DATABASE" sourceWB.datasources[0].connections[0].username = "benl"

It does not seem like Document API allows a way for the user to give the password for the database. Does it assume the password is the same in "NEW-DATABSE" as it was in the old database? I don't understand how it can ask for a database user but not password.

YEM-1 avatar May 28 '18 01:05 YEM-1

Hi guys, Sorry but rookie to Python and API syntax... Though I did manage to adapt the TSC API codes to my own stuff (server, site, db, etc...), I couldn't find a way to make these 3 lines of code from document API to work fine !!

First, I have not been able to make this code find my workbook from its name !! Server problem ? Name ? What is wrong ? Does it need the whole path to the physical file ? assumed it was working n the server, then try full path but didn't work either.

As a resume : I am lost ;) THANKS in advance for your help.

from tableaudocumentapi import Workbook sourceWB = Workbook('WorkbookToUpdate.twb') sourceWB.datasources[0].connections[0].server = "MY-NEW-SERVER" sourceWB.datasources[0].connections[0].dbname = "NEW-DATABASE" sourceWB.datasources[0].connections[0].username = "benl" sourceWB.save()

gmkey69 avatar Oct 15 '18 13:10 gmkey69

@benlower Hi! I am surprised this is of more interest - or maybe I am missing something. I would imagine MANY would like to have two published data sources (exactly the same with the exception of the connection string) - call them "stg" and "prod". Those data sources are likely being refreshed regularly. Now, I as the admin have a .twb with connections to the published data sources (which are federated btw). What I would like to do is take the ONE .twb workbook which is using the "stg" data source on server. Id like to save over the existing workbook, then switch the "stg" to "prod" datasource (which are exactly the same besides the connection details) and publish. What am i missing? I would think (while dangerous in many circumstances) I could replace a "datasource".

andymiller-og avatar Oct 08 '19 16:10 andymiller-og

@YEM-1 (or anyone else that is interested) I'm fairly confident that a .twbx/.twb file does not store a password. I would assume this was a deliberate security decision by the Tableau team. It certainly seems like a wise decision to me.

pjcpjc avatar Aug 06 '20 19:08 pjcpjc

@YEM-1 (or anyone else that is interested) I'm fairly confident that a .twbx/.twb file does not store a password. I would assume this was a deliberate security decision by the Tableau team. It certainly seems like a wise decision to me.

Published data sources contain embedded passwords.

YEM-1 avatar Aug 07 '20 00:08 YEM-1

@YEM-1 (or anyone else that is interested) I'm fairly confident that a .twbx/.twb file does not store a password. I would assume this was a deliberate security decision by the Tableau team. It certainly seems like a wise decision to me.

Published data sources contain embedded passwords.

Well, I suppose that is easy to say. Do you have any evidence the password is present in the .twb/.twbx file? The .twb file is simply XML, its easy to examine. There is also the behavior of Tableau itself, which seems to repeatedly request passwords in a manner indicating that the .twb/.twbx files aren't archiving them.

pjcpjc avatar Aug 07 '20 01:08 pjcpjc

Hi @YEM-1 the twb/twbx/tds/tdsx does not contain the password so the document api does not provide a way to embed the password. Embedded passwords are only a concept in the context of Tableau Server, and they are stored in a secure manner separate from the datasource documents as you would expect from any secure application that needs to store and handle user provided credentials.

graysonarts avatar Aug 07 '20 02:08 graysonarts

@RussTheAerialist Thanks! So say we all.

pjcpjc avatar Aug 07 '20 16:08 pjcpjc

I'm currently looking for a way to replace one published datasource with another. I'm not sure if this is currently possible (just started exploring the Document API)... but anyway I think an API contract like this would be nice to have:

WB = Workbook('..\data\myDownloadedWB.twbx') newDS = Datasource.from_file('..\data\myDownloadedDS.tdsx') WB.datasources[0].save(newDS)

An even better solution would be to let us do this directly on the server! Currently I'm using the REST API to download/publish

Trones21 avatar Feb 28 '23 22:02 Trones21