Skip to content

fix(pubsub): handle internal metadata changes in google-api-core - #18037

Open
chalmerlowe wants to merge 1 commit into
mainfrom
fix/pubsub-gapic-callable-metadata
Open

fix(pubsub): handle internal metadata changes in google-api-core#18037
chalmerlowe wants to merge 1 commit into
mainfrom
fix/pubsub-gapic-callable-metadata

Conversation

@chalmerlowe

@chalmerlowe chalmerlowe commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Problem

The test_init_default_client_info tests in google-cloud-pubsub (for both Publisher and Subscriber) were brittle because they peeked into the private internal attributes of _GapicCallable (from google-api-core) to verify metadata.
Recent refactoring in google-api-core renamed/removed the _metadata attribute, causing these tests to fail with AttributeError: '_GapicCallable' object has no attribute '_metadata'.

Solution

Refactored test_init_default_client_info in test_publisher_client.py and test_subscriber_client.py to use mocking instead of peeking into internal state.

  • The tests now use unittest.mock.patch to intercept calls to google.api_core.gapic_v1.method.wrap_method.
  • We verify that wrap_method is called with the expected client_info object.
  • We assert that the client_info contains the correct library version string (e.g., gccl/x.y.z).

Why this is important

  • Robustness: Tests are no longer dependent on internal implementation details or private attributes of downstream libraries (google-api-core).
  • Future-Proof: Prevents test failures when internal state is refactored, as long as the public-facing helper signature (wrap_method) remains stable.
  • Consistency: Aligns with the testing patterns already adopted by other modern clients in this monorepo (e.g., google-cloud-bigquery-storage).

Blocks: #17642

@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 unit tests for both the publisher and subscriber clients to handle internal changes in the google-api-core library's _GapicCallable. Specifically, it safely retrieves metadata from wrapped methods by falling back to _default_metadata if _metadata is not present. Additionally, some minor import cleanups were performed. There are no review comments, and I have no feedback to provide.

@chalmerlowe
chalmerlowe marked this pull request as ready for review August 10, 2026 10:17
@chalmerlowe
chalmerlowe requested a review from a team as a code owner August 10, 2026 10:17
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