tableau / server-client-python

A Python library for the Tableau Server REST API
https://tableau.github.io/server-client-python/
MIT License
648 stars 416 forks source link

fix: pop from empty list #1404

Open PatrickfBraz opened 4 weeks ago

PatrickfBraz commented 4 weeks ago

Context

I am using the client to ingest Tableau metadata into the metadata platform called DataHub. When searching for metadata via GraphQL query, the client is returning the error shown in the message below. From my understanding of the code, this error can happen in 2 moments: at the end of pagination or at the beginning. In any case, the non-existence of the key sought within the json will cause extract_values to return an empty list and therefore trigger the IndexError when trying to call the pop method.

Traceback

line 713, in get_connection_objects pages = self.tableau_source.server.metadata.paginated_query(query, variables=variables)["pages"] # type: ignore File "/usr/local/lib/python3.10/site-packages/tableauserverclient/server/endpoint/endpoint.py", line 205, in wrapper return func(self, *args, **kwargs) File "/usr/local/lib/python3.10/site-packages/tableauserverclient/server/endpoint/metadata_endpoint.py", line 125, in paginated_query has_another_page, cursor = get_page_info(results) File "/usr/local/lib/python3.10/site-packages/tableauserverclient/server/endpoint/metadata_endpoint.py", line 45, in get_page_info next_page = extract_values(result, "hasNextPage").pop() IndexError: pop from empty list

Aditional information

The query we try to execute through the method client.server.metadata.paginated_query(...) is the following:

query customSQLDatasources($first: Int, $afterToken: String, $datasource_ids: [ID]) {
    customSQLTablesConnection(first: $first, after: $afterToken, filter: {idWithin: $datasource_ids}) {
        nodes {
            id
            name
            query
            columns {
                id
                name
                remoteType
                description
                referencedByFields {
                    datasource {
                        __typename
                        id
                        name
                        upstreamTables {
                            id
                            name
                            isEmbedded
                            database {
                                name
                            }
                            schema
                            fullName
                            connectionType
                        }
                        ... on PublishedDatasource {
                            projectName
                            luid
                        }
                        ... on EmbeddedDatasource {
                            workbook {
                                id
                                name
                                projectName
                                luid
                            }
                        }
                    }
                }
            }
            tables {
                id
                name
                isEmbedded
                database {
                    name
                }
                schema
                fullName
                connectionType
                description
                columns {
                    name
                    remoteType
                }
            }
            database {
                name
                connectionType
            }
        }
        pageInfo {
            hasNextPage
            endCursor
        }
        totalCount
    }
}
salesforce-cla[bot] commented 4 weeks ago

Thanks for the contribution! Before we can merge this, we need @PatrickfBraz to sign the Salesforce Inc. Contributor License Agreement.

PatrickfBraz commented 4 weeks ago

Signed image