Skip to content

fix(gapic-generator): forward client_options to Extended Operations sub-clients - #19293

Draft
chalmerlowe wants to merge 5 commits into
mainfrom
fix/gapic-extended-ops-universe
Draft

chalmerlowe wants to merge 5 commits into
mainfrom
fix/gapic-extended-ops-universe

Conversation

@chalmerlowe

@chalmerlowe chalmerlowe commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Generated Extended Operations sub-client properties (_zone_operations_client, _region_operations_client, _global_operations_client, _global_organization_operations_client) previously instantiated their operations clients with only credentials and transport, dropping parent client_options (including universe_domain, api_endpoint, api_audience, client_cert_source, scopes, and quota_project_id). As a result, polling an ExtendedOperation on a client configured for a custom universe_domain or api_endpoint routed operation polling back to the default googleapis.com endpoint.

This PR updates the gapic-generator templates (~216 lines of production template changes + two-tier tests) so Extended Operations sub-clients inherit client_options from the parent client:

  • transports/base.py.j2: Defines _inherit_universe_in_client_options (gated on Extended Operations services) with child.api_endpoint -> child.universe_domain -> parent.api_endpoint -> parent.universe_domain -> GOOGLE_CLOUD_UNIVERSE_DOMAIN -> default precedence, clearing credentials_file and api_key when forwarding alongside already-resolved credentials to avoid DuplicateCredentialArgs, without mutating caller inputs. Preserves normalized client_options on the transport and passes them when lazily constructing Extended Operations sub-clients.
  • client.py.j2: Forwards normalized client_options onto both newly instantiated and prebuilt transports (safely guarding custom/duck-typed transports). Non-Extended-Operations services produce zero generated diff.
  • test_%service.py.j2: Adds a lean per-service test suite (~310 lines) hitting 100% branch coverage on generated client.py and transports/base.py without bloating regenerated multi-service libraries like google-cloud-compute.
  • tests/unit/generator/test_extended_ops_universe.py: Runs the exhaustive _inherit_universe_in_client_options boundary/mutation matrix and non-Extended-Operations template-isolation checks once in gapic-generator unit tests.

Follow-up PR will regenerate google-cloud-compute, google-cloud-compute-v1beta, and preview-packages/google-cloud-compute once this generator change lands.

Internal tracking: b/589828846

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the GAPIC generator templates to support propagating client options, such as universe domains and API endpoints, to extended operations sub-clients, including a fallback compatibility implementation for older google-api-core versions and extensive unit tests. The review feedback highlights a critical missing import of client_options_lib in the base transport template that would cause a runtime NameError, as well as a recommended improvement to use getattr when checking credentials_file to prevent potential AttributeErrors.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant