bryanthowell-tableau / tableau_tools

Package containing Tableau REST API, XML modification, tabcmd and repository tools
Other
215 stars 86 forks source link

over-writing custom sql queries no longer working #86

Closed HudsonMC16 closed 4 years ago

HudsonMC16 commented 4 years ago

In a previous version of tableau tools, I was able to use the following code to create workbooks from a template workbook with different custom sql queries:

sql = self.GenerateSQL()
tf = TableauFileManager.open(filename="template.twb")
ds = tf.tableau_document.datasources[0]
ds.main_table_relation.text = sql

but this code now results in the following error on the last line:

Exception has occurred: AttributeError
'NoneType' object has no attribute 'text'

It appears the structure of the tableau_document class has changed? Is it still possible to manipulate custom sql queries in this manner?

bryanthowell-tableau commented 4 years ago

Hi Hudson, I did make some significant changes to the tableau_documents portion of the library, specifically these areas, to try and give a more unified syntax. If you look in the README at sections 2.4.5, the new naming conventions are there. You access the Custom SQL via 'TableauDatasource.tables.main_custom_sql' now rather than the old way.

Let me know if you hit any errors once you updated based on the new properties.

HudsonMC16 commented 4 years ago

Thanks, Bryant! I will try this and see how it goes.

HudsonMC16 commented 4 years ago

ah, Unfortunately, I have to report that this isn't quite working. Despite the template file clearly containing a pre-existing custom sql string, I'm getting this error:

InvalidOptionException('Data Source does not have Custom SQL defined')

when using the following code:

sql = self.GenerateSQL()
tf = TableauFileManager.open(filename="template.twb")
ds = tf.datasources[0]
ds.tables.main_custom_sql = sql

It looks like, from the tableau_documents code here: https://github.com/bryantbhowell/tableau_tools/blob/1bd2dfed5c56dd2aec64eeb30572f960e8413af3/tableau_documents/table_relations.py#L49

you're checking if the type is stored-proc. In my case, the main_table_type is "custom-sql"

EDIT: Actually, I take that back. ds.main_table_type is "custom-sql". ds.tables.main_table.attrib['type'] is "text". Not sure if these should match, or what exactly the meaning of these two parameters is.

HudsonMC16 commented 4 years ago

Should we re-open this issue?