googleapis / python-bigquery

Apache License 2.0
746 stars 306 forks source link

Use original Client's `client_info` in `_ensure_bqstorage_client` to create `BigQueryReadClient` #1961

Open b-schmeling opened 5 months ago

b-schmeling commented 5 months ago

Problem

If I set the user_agent in the client_info in a BigQueryClient, the resultant storage client from _ensure_bqstorage_client does not have the user agent I set.

This is visible in the code here:

def _ensure_bqstorage_client(
        self,
        bqstorage_client: Optional[
            "google.cloud.bigquery_storage.BigQueryReadClient"
        ] = None,
        client_options: Optional[google.api_core.client_options.ClientOptions] = None,
        client_info: Optional[
            "google.api_core.gapic_v1.client_info.ClientInfo"
        ] = DEFAULT_BQSTORAGE_CLIENT_INFO,
    ) -> Optional["google.cloud.bigquery_storage.BigQueryReadClient"]:
       ...

        if bqstorage_client is None:  # pragma: NO COVER
            bqstorage_client = bigquery_storage.BigQueryReadClient(
                credentials=self._credentials,
                client_options=client_options,
                client_info=client_info,  # type: ignore  # (None is also accepted)
            )

Solution

For _ensure_bqstorage_client to default to using the original client's client_info if no client_info is provided in the params.

The only part of the client_info that I really need in both clients is the user_agent, so alternatively I would be fully satisfied if just the user agent were propagated to the storage client.

Alternatives

For now, I believe I will have to manually create the bqstorage client with my own client_info.

Additional context