Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Create new instance of client info rather than stomping on shared instance. #2161

Closed
crwilcox opened this issue Jul 20, 2018 · 3 comments
Closed
Assignees
Labels
lang: python Issues specific to Python. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. yoshi

Comments

@crwilcox
Copy link

crwilcox commented Jul 20, 2018

While reviewing a new client @tseaver noticed a bit that may need revising.

Quoting from https://github.com/GoogleCloudPlatform/google-cloud-python/pull/5665/files/12676aaf08dc795f2216f9441896cfae54edd382#diff-198e257d2c267a0bc3e3d2f3e77ec561

https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/dlp/google/cloud/dlp_v2/gapic/dlp_service_client.py#L173

        if client_info is None:
            client_info = (
                google.api_core.gapic_v1.client_info.DEFAULT_CLIENT_INFO)
        client_info.gapic_version = _GAPIC_LIBRARY_VERSION

This bit is problematic -- the DEFAULT_CLIENT_INFO instance is going to be scribbled on by every library generated this way, which means that each time an app instantiates a generated client, they all use the last-instantiated one's gapic_version.

Rather than reuse the instance, we should be constructing a new one here, e.g.:

        if client_info is None:  # create a new instance
            client_info = (
                google.api_core.gapic_v1.client_info.ClientInfo(
                    gapic_version=_GAPIC_LIBRARY_VERSION)
        else:  # update caller-supplied instance
            client_info.gapic_version = _GAPIC_LIBRARY_VERSION
@crwilcox crwilcox added lang: python Issues specific to Python. yoshi labels Jul 20, 2018
@tseaver tseaver added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. labels Aug 8, 2018
@jbolinger
Copy link
Contributor

@crwilcox @lukesneeringer this has been quiet for awhile - is it still relevant?

@tseaver
Copy link
Contributor

tseaver commented Sep 4, 2018

@jbolinger The generator is still emitting code which has this flaw (@crwilcox re-genned several libraries over the weekend, ant their clients all have it).

@tseaver
Copy link
Contributor

tseaver commented Sep 4, 2018

These snips all scribble on the global DEFAULT_CLIENT_INFO:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lang: python Issues specific to Python. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. yoshi
Projects
None yet
Development

No branches or pull requests

4 participants