Skip to content

feat(generator): gapic generator centralization routing#17816

Open
hebaalazzeh wants to merge 11 commits into
mainfrom
feat/gapic-generator-centralization-routing
Open

feat(generator): gapic generator centralization routing#17816
hebaalazzeh wants to merge 11 commits into
mainfrom
feat/gapic-generator-centralization-routing

Conversation

@hebaalazzeh

@hebaalazzeh hebaalazzeh commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

This PR updates the generator templates to rely on the centralized endpoint routing and universe domain logic from google-api-core.

Since PR #17799 successfully centralized these helpers (get_api_endpoint, get_universe_domain, get_default_mtls_endpoint) into google/api_core/universe.py, we no longer need the generator to produce fallback implementations for them. The generated _compat.py will now import these directly from universe.py.

(Note: This replaces the previous PR #17746 which was auto-closed due to a deleted base branch).

@hebaalazzeh hebaalazzeh self-assigned this Jul 21, 2026

@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 introduces a new compatibility template _compat.py.j2 to provide fallback implementations for get_default_mtls_endpoint, get_api_endpoint, and get_universe_domain when they are not available in google.api_core.universe. The client templates are updated to delegate these operations to the new compatibility module, and redundant unit tests are removed from the generated test suites. The review feedback highlights that both get_api_endpoint in _compat.py.j2 and _get_api_endpoint in client.py.j2 can return None under certain conditions, and recommends updating their return type annotations to Optional[str] for better type safety.

@hebaalazzeh
hebaalazzeh marked this pull request as ready for review July 21, 2026 21:58
@hebaalazzeh
hebaalazzeh requested a review from a team as a code owner July 21, 2026 21:58
@hebaalazzeh
hebaalazzeh force-pushed the feat/gapic-generator-centralization-routing branch from b8ed069 to b7054c2 Compare July 21, 2026 23:14
@hebaalazzeh

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 introduces a compatibility module template _compat.py.j2 to centralize fallback logic for older versions of google-api-core, updating the generator and client templates to import and use these shared utilities. Feedback on the changes highlights two critical issues regarding generated files: first, the new mock.patch("os.path.exists", ...) in the golden files is missing from the generator's template test_%service.py.j2; second, the new test file test__compat.py was added directly to a golden directory without a corresponding template, which will cause integration test failures.

config_file_content = json.dumps(config_data)
m = mock.mock_open(read_data=config_file_content)
with mock.patch("builtins.open", m):
with mock.patch("builtins.open", m), mock.patch("os.path.exists", side_effect=lambda path: os.path.basename(path) == config_filename):

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.

high

The addition of mock.patch("os.path.exists", ...) is present in the golden files (such as this one) but is missing from the generator template test_%service.py.j2. Since golden files are entirely generated, any manual changes to them will be overwritten the next time the generator is run. Please update the test_%service.py.j2 template to include this mock patch so that it is correctly generated for all clients.

References
  1. Do not suggest manual code modifications, optimizations, or style fixes for generated files, as any changes should be implemented in the generator or templates to prevent them from being overwritten.

from google.cloud.storagebatchoperations_v1 import _compat


def test_setup_request_id_fallback():

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.

high

This test file test__compat.py is added directly to the storagebatchoperations golden directory, but there is no corresponding test__compat.py.j2 template in gapic/templates/tests/unit/gapic/. If this file is not generated by the generator, the integration tests (which compare the generated output with the golden directory) will fail due to the extra file in the golden directory. If _compat.py needs to be tested, we should either create a test__compat.py.j2 template so it is generated for all clients, or move this test to the generator's own unit tests.

References
  1. Do not suggest manual code modifications, optimizations, or style fixes for generated files, as any changes should be implemented in the generator or templates to prevent them from being overwritten.

@hebaalazzeh
hebaalazzeh force-pushed the feat/gapic-generator-centralization-routing branch from f61bfa7 to a89c8ca Compare July 23, 2026 17:20
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