4 Replies Latest reply on Mar 23, 2020 8:27 AM by Mike Davis

    Ask data not showing anything when publishing datasource programatically

    Kevin Sallee



      I used sample code from Tableau hyper API to create a data source. It's pretty straightforward code, nothing unusual:

      def run_insert_data_into_single_table():
          An example demonstrating a simple single-table Hyper file including table creation and data insertion with different types
          print("EXAMPLE - Insert data into a single table within a new Hyper file")
          path_to_database = Path("customer.hyper")
          # Starts the Hyper Process with telemetry enabled to send data to Tableau.
          # To opt out, simply set telemetry=Telemetry.DO_NOT_SEND_USAGE_DATA_TO_TABLEAU.
          with HyperProcess(telemetry=Telemetry.DO_NOT_SEND_USAGE_DATA_TO_TABLEAU) as hyper:
              # Creates new Hyper file "customer.hyper".
              # Replaces file with CreateMode.CREATE_AND_REPLACE if it already exists.
              with Connection(endpoint=hyper.endpoint,
                              create_mode=CreateMode.CREATE_AND_REPLACE) as connection:
                  # The rows to insert into the "Extract"."Extract" table.
                  data_to_insert = [
                      ["DK-13375", "Dennis Kane", 518, "Consumer"],
                      ["EB-13705", "Ed Braxton", 815, "Corporate"]
                  with Inserter(connection, extract_table) as inserter:
                  # The table names in the "Extract" schema (the default schema).
                  table_names = connection.catalog.get_table_names("Extract")
                  print(f"Tables available in {path_to_database} are: {table_names}")
                  # Number of rows in the "Extract"."Extract" table.
                  # `execute_scalar_query` is for executing a query that returns exactly one row with one column.
                  row_count = connection.execute_scalar_query(query=f"SELECT COUNT(*) FROM {extract_table.table_name}")
                  print(f"The number of rows in table {extract_table.table_name} is {row_count}.")
              print("The connection to the Hyper file has been closed.")
          print("The Hyper process has been shut down.")


      I then publish this file using tableau server client, again, nothing out of this world:

      with server.auth.sign_in(tableau_auth):
          datasources, pagination_item = server.datasources.get()
          all_projects, pagination_item = server.projects.get()
          project = next((project for project in all_projects if project.name == "Project"), None)
          if project:
              file_path = "customer.hyper"
              new_datasource = TSC.DatasourceItem(project.id)
              new_datasource = server.datasources.publish(
                  new_datasource, file_path, TSC.Server.PublishMode.CreateNew, as_job=True


      So it's publishing a local file as a Data Source on my server.
      All that works fine, but the "Ask data" panel only has "number of records", and no dimensions are listed. I can't (if I understood correctly) refresh the data or anything, since it does not have a connection anymore to anything.

      But if I want to do a workbook, the data is there, and works. It's just not available in "Ask Data".


      Why is that? Can I do something to get "Ask data" working when programmatically creating data sources?