Skip to content

fix(api_core): support suppress_metrics_header fallback in AuthMetadataPlugin - #18029

Merged
ohmayr merged 10 commits into
mainfrom
fix-api-core-grpc-helpers-test
Aug 7, 2026
Merged

ohmayr merged 10 commits into
mainfrom
fix-api-core-grpc-helpers-test

Conversation

@ohmayr

@ohmayr ohmayr commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

PR #17616 introduced logic in grpc_helpers.py to pass suppress_metrics_header=True to google.auth.transport.grpc.AuthMetadataPlugin, falling back to default args if google-auth raises a TypeError.

Following the release of google-auth==2.56.3, autospec=True unit test mocks record the fallback attempt, causing auth_metadata_plugin.assert_called_once_with to fail due to multiple invocations.

Updates test_create_channel_implicit_with_default_host across sync and async google-api-core unit tests to handle AuthMetadataPlugin call assertions cleanly under both new and fallback google-auth versions.

@ohmayr
ohmayr requested a review from a team as a code owner August 7, 2026 18:56

@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 a unit test in test_grpc_helpers.py to handle different versions of google-auth by catching assertion errors when suppress_metrics_header is passed. The reviewer identified a critical issue where using assert_called_once_with in the fallback block will fail because the mock's call count is incremented to 2 during the test execution. They provided a code suggestion to use assert_called_with instead and verify that the call count is either 1 or 2.

Comment thread packages/google-api-core/tests/unit/test_grpc_helpers.py Outdated

@daniel-sanche daniel-sanche 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.

LGTM, with suggestions

auth_metadata_plugin.assert_called_once_with(
mock.sentinel.credentials, mock.sentinel.Request, default_host=default_host
)
assert auth_metadata_plugin.call_count in (1, 2)

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.

nit: can you add a comment explaining why it can be one or two?

default_host=default_host,
suppress_metrics_header=True,
)
except AssertionError:

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.

Maybe instead of a try/catch here, we should have separate test logic depending on the version of google-auth installed?

SUPPORTS_SUPPRESS_METRICS = parse_version_to_tuple(google.auth.__version__) >= (2, 57, 0)

if SUPPORTS_SUPPRESS_METRICS:
    auth_metadata_plugin.assert_called_once_with(
        mock.sentinel.credentials,
        mock.sentinel.Request,
        default_host=default_host,
        suppress_metrics_header=True,
    )
else:
    # In older google-auth, the first call raises TypeError and falls back to default args
    assert auth_metadata_plugin.call_count == 2
    auth_metadata_plugin.assert_called_with(
        mock.sentinel.credentials,
        mock.sentinel.Request,
        default_host=default_host,
    )

@ohmayr
ohmayr merged commit dd2000d into main Aug 7, 2026
43 checks passed
@ohmayr
ohmayr deleted the fix-api-core-grpc-helpers-test branch August 7, 2026 21:04
@release-please release-please Bot mentioned this pull request Aug 7, 2026
codyoss pushed a commit that referenced this pull request Aug 24, 2026
🤖 I have created a release *beep* *boop*
---


<details><summary>django-google-spanner: 5.0.1</summary>

##
[5.0.1](django-google-spanner-v5.0.0...django-google-spanner-v5.0.1)
(2026-08-21)


### Bug Fixes

* **django-spanner:** declare django dependency in setup.py
([#18044](#18044))
([c341469](c341469))


### Documentation

* **django-spanner, common-protos:** centralize CONTRIBUTING.rst
pointers
([#18041](#18041))
([2b056ab](2b056ab))
</details>

<details><summary>gapic-generator: 1.39.0</summary>

##
[1.39.0](gapic-generator-v1.38.0...gapic-generator-v1.39.0)
(2026-08-21)


### Features

* **generator:** add fallback compatibility imports for google-api-core
helpers
([#17999](#17999))
([9c13ae2](9c13ae2))


### Bug Fixes

* **generator:** check for api_version header in metadata list
([#18015](#18015))
([0e63510](0e63510))
* **generator:** move version checks after __all__ in __init__.py
temlate
([#18100](#18100))
([d0efb4d](d0efb4d))
* **generator:** switch core_deps_from_source to DEFAULT_PYTHON_VERSION
([#18050](#18050))
([895ffa2](895ffa2))


### Documentation

* **handwritten:** centralize CONTRIBUTING.rst pointers
([#17642](#17642))
([23b9499](23b9499))
</details>

<details><summary>gcp-sphinx-docfx-yaml: 3.3.2</summary>

##
[3.3.2](gcp-sphinx-docfx-yaml-v3.3.1...gcp-sphinx-docfx-yaml-v3.3.2)
(2026-08-21)


### Documentation

* **handwritten:** centralize CONTRIBUTING.rst pointers
([#17642](#17642))
([23b9499](23b9499))
</details>

<details><summary>google-ads-admanager: 0.10.2</summary>

##
[0.10.2](google-ads-admanager-v0.10.1...google-ads-admanager-v0.10.2)
(2026-08-21)


### Features

* update googleapis and regenerate
([#18087](#18087))
([db1622a](db1622a))
</details>

<details><summary>google-ads-datamanager: 0.9.2</summary>

##
[0.9.2](google-ads-datamanager-v0.9.1...google-ads-datamanager-v0.9.2)
(2026-08-21)


### Features

* update googleapis and regenerate
([#18087](#18087))
([db1622a](db1622a))
</details>

<details><summary>google-api-core: 2.35.0</summary>

##
[2.35.0](google-api-core-v2.34.0...google-api-core-v2.35.0)
(2026-08-21)


### Features

* **api_core:** add deprecation warning for grpcio &lt; 1.83.0 for PQC
([#18045](#18045))
([7e2e23e](7e2e23e))


### Bug Fixes

* **api_core:** improve rest path validation
([#17753](#17753))
([63bfb96](63bfb96))
* **api_core:** support suppress_metrics_header fallback in
AuthMetadataPlugin
([#18029](#18029))
([dd2000d](dd2000d))


### Documentation

* **handwritten:** centralize CONTRIBUTING.rst pointers
([#17642](#17642))
([23b9499](23b9499))
</details>

<details><summary>google-apps-chat: 0.10.5</summary>

##
[0.10.5](google-apps-chat-v0.10.4...google-apps-chat-v0.10.5)
(2026-08-21)


### Features

* update googleapis and regenerate
([#18087](#18087))
([db1622a](db1622a))
* update sources and regenerate
([#18164](#18164))
([5ff8274](5ff8274))
</details>

<details><summary>google-auth: 2.57.0</summary>

##
[2.57.0](google-auth-v2.56.3...google-auth-v2.57.0)
(2026-08-21)


### Features

* **auth:** add deprecation warning for grpcio &lt; 1.83.0 (PQC support)
([#18070](#18070))
([68bdaba](68bdaba))


### Bug Fixes

* **auth:** parse hostname for mTLS and PSC endpoint certificate rotat…
([#18153](#18153))
([b642373](b642373))
* **auth:** prevent TypeError and support home-dir cert fallback for X…
([#18016](#18016))
([b9a1379](b9a1379))


### Documentation

* **handwritten:** centralize CONTRIBUTING.rst pointers
([#17642](#17642))
([23b9499](23b9499))
</details>

<details><summary>google-auth-httplib2: 0.4.2</summary>

##
[0.4.2](google-auth-httplib2-v0.4.1...google-auth-httplib2-v0.4.2)
(2026-08-21)


### Documentation

* **handwritten:** centralize CONTRIBUTING.rst pointers
([#17642](#17642))
([23b9499](23b9499))
</details>

<details><summary>google-auth-oauthlib: 1.4.1</summary>

##
[1.4.1](google-auth-oauthlib-v1.4.0...google-auth-oauthlib-v1.4.1)
(2026-08-21)


### Bug Fixes

* **google-auth-oauthlib:** prevent port re-use on windows
([#18166](#18166))
([e20796a](e20796a))


### Documentation

* **handwritten:** centralize CONTRIBUTING.rst pointers
([#17642](#17642))
([23b9499](23b9499))
</details>

<details><summary>google-cloud-alloydb: 0.11.1</summary>

##
[0.11.1](google-cloud-alloydb-v0.11.0...google-cloud-alloydb-v0.11.1)
(2026-08-21)


### Features

* update sources and regenerate
([#18164](#18164))
([5ff8274](5ff8274))
</details>

<details><summary>google-cloud-audit-log: 0.6.2</summary>

##
[0.6.2](google-cloud-audit-log-v0.6.1...google-cloud-audit-log-v0.6.2)
(2026-08-21)


### Bug Fixes

* `google-cloud-audit-log` wheel installs unintended top-level `docs`
package
([#17271](#17271))
([ad99ed1](ad99ed1))
</details>

<details><summary>google-cloud-auditmanager: 0.3.1</summary>

##
[0.3.1](google-cloud-auditmanager-v0.3.0...google-cloud-auditmanager-v0.3.1)
(2026-08-21)


### Features

* update googleapis and regenerate
([#18087](#18087))
([db1622a](db1622a))
* update sources and regenerate
([#18164](#18164))
([5ff8274](5ff8274))
</details>

<details><summary>google-cloud-automl: 2.20.1</summary>

##
[2.20.1](google-cloud-automl-v2.20.0...google-cloud-automl-v2.20.1)
(2026-08-21)


### Bug Fixes

* **automl:** remove unused libcst extra and constraints
([#18056](#18056))
([9ba4449](9ba4449))
</details>

<details><summary>google-cloud-bigquery: 3.44.0</summary>

##
[3.44.0](google-cloud-bigquery-v3.43.0...google-cloud-bigquery-v3.44.0)
(2026-08-21)


### Features

* add PendingDeprecationWarning for to_dataframe and to_arrow conversion
methods
([#18021](#18021))
([6bebf30](6bebf30))
* **bigquery:** add PendingDeprecationWarning for from_dataframe methods
([#18048](#18048))
([b84b754](b84b754))
* **bigquery:** support queryResultsFormat and compressionCodec in
query_and_wait
([#18027](#18027))
([d172408](d172408))
* check python and dependency versions in bigquery and ndb
([#18075](#18075))
([62ff6f3](62ff6f3))


### Documentation

* **handwritten:** centralize CONTRIBUTING.rst pointers
([#17642](#17642))
([23b9499](23b9499))
</details>

<details><summary>google-cloud-bigquery-reservation: 1.26.0</summary>

##
[1.26.0](google-cloud-bigquery-reservation-v1.25.0...google-cloud-bigquery-reservation-v1.26.0)
(2026-08-21)


### Features

* update googleapis and regenerate
([#18087](#18087))
([db1622a](db1622a))
</details>

<details><summary>google-cloud-bigquery-storage: 2.41.0</summary>

##
[2.41.0](google-cloud-bigquery-storage-v2.40.0...google-cloud-bigquery-storage-v2.41.0)
(2026-08-21)


### Features

* add pandas-gbq to optional extras
([#18020](#18020))
([fe91d93](fe91d93))
* **bigquery-storage:** add deprecation warning for to_dataframe
([#18022](#18022))
([57e7822](57e7822))
* update sources and regenerate
([#18164](#18164))
([5ff8274](5ff8274))


### Bug Fixes

* **storage:** support updated GapicCallable metadata in tests
([#18031](#18031))
([24fe2e3](24fe2e3))


### Documentation

* **handwritten:** centralize CONTRIBUTING.rst pointers
([#17642](#17642))
([23b9499](23b9499))
</details>

<details><summary>google-cloud-bigtable: 2.43.0</summary>

##
[2.43.0](google-cloud-bigtable-v2.42.0...google-cloud-bigtable-v2.43.0)
(2026-08-21)


### Features

* update sources and regenerate
([#18164](#18164))
([5ff8274](5ff8274))


### Documentation

* **handwritten:** centralize CONTRIBUTING.rst pointers
([#17642](#17642))
([23b9499](23b9499))
</details>

<details><summary>google-cloud-build: 3.39.0</summary>

##
[3.39.0](google-cloud-build-v3.38.1...google-cloud-build-v3.39.0)
(2026-08-21)


### Features

* update sources and regenerate
([#18164](#18164))
([5ff8274](5ff8274))
</details>

<details><summary>google-cloud-commerceproducer: 0.1.2</summary>

##
[0.1.2](google-cloud-commerceproducer-v0.1.1...google-cloud-commerceproducer-v0.1.2)
(2026-08-21)


### Features

* update googleapis and regenerate
([#18087](#18087))
([db1622a](db1622a))
</details>

<details><summary>google-cloud-compute: 1.51.0</summary>

##
[1.51.0](google-cloud-compute-v1.50.0...google-cloud-compute-v1.51.0)
(2026-08-21)


### Features

* update googleapis and regenerate
([#18087](#18087))
([db1622a](db1622a))
</details>

<details><summary>google-cloud-compute-v1beta: 0.12.2</summary>

##
[0.12.2](google-cloud-compute-v1beta-v0.12.1...google-cloud-compute-v1beta-v0.12.2)
(2026-08-21)


### Features

* update googleapis and regenerate
([#18087](#18087))
([db1622a](db1622a))
</details>

<details><summary>google-cloud-core: 2.7.0</summary>

##
[2.7.0](google-cloud-core-v2.6.1...google-cloud-core-v2.7.0)
(2026-08-21)


### Features

* **core:** implement PEP 0810 explicit lazy imports in
google-cloud-core
([#18052](#18052))
([5a7ed02](5a7ed02))


### Bug Fixes

* use lowercase x-goog-api-client header
([#18064](#18064))
([d465d1e](d465d1e))


### Documentation

* **handwritten:** centralize CONTRIBUTING.rst pointers
([#17642](#17642))
([23b9499](23b9499))
</details>

<details><summary>google-cloud-dataform: 0.11.3</summary>

##
[0.11.3](google-cloud-dataform-v0.11.2...google-cloud-dataform-v0.11.3)
(2026-08-21)


### Features

* update googleapis and regenerate
([#18087](#18087))
([db1622a](db1622a))
* update sources and regenerate
([#18164](#18164))
([5ff8274](5ff8274))
</details>

<details><summary>google-cloud-datastore: 2.26.1</summary>

##
[2.26.1](google-cloud-datastore-v2.26.0...google-cloud-datastore-v2.26.1)
(2026-08-21)


### Documentation

* **handwritten:** centralize CONTRIBUTING.rst pointers
([#17642](#17642))
([23b9499](23b9499))
</details>

<details><summary>google-cloud-dns: 0.37.1</summary>

##
[0.37.1](google-cloud-dns-v0.37.0...google-cloud-dns-v0.37.1)
(2026-08-21)


### Documentation

* **handwritten:** centralize CONTRIBUTING.rst pointers
([#17642](#17642))
([23b9499](23b9499))
</details>

<details><summary>google-cloud-documentai-toolbox: 0.17.3</summary>

##
[0.17.3](google-cloud-documentai-toolbox-v0.17.2...google-cloud-documentai-toolbox-v0.17.3)
(2026-08-21)


### Bug Fixes

* **documentai-toolbox:** contain split_pdf output to output_path
([#18063](#18063))
([d206212](d206212))
* **documentai-toolbox:** enable autoescape in export_hocr_str
([#18140](#18140))
([0d671d2](0d671d2))


### Documentation

* **handwritten:** centralize CONTRIBUTING.rst pointers
([#17642](#17642))
([23b9499](23b9499))
</details>

<details><summary>google-cloud-error-reporting: 1.16.1</summary>

##
[1.16.1](google-cloud-error-reporting-v1.16.0...google-cloud-error-reporting-v1.16.1)
(2026-08-21)


### Documentation

* **handwritten:** centralize CONTRIBUTING.rst pointers
([#17642](#17642))
([23b9499](23b9499))
</details>

<details><summary>google-cloud-firestore: 2.29.0</summary>

##
[2.29.0](google-cloud-firestore-v2.28.1...google-cloud-firestore-v2.29.0)
(2026-08-21)


### Features

* update googleapis and regenerate
([#18087](#18087))
([db1622a](db1622a))


### Documentation

* **handwritten:** centralize CONTRIBUTING.rst pointers
([#17642](#17642))
([23b9499](23b9499))
</details>

<details><summary>google-cloud-iam: 2.25.0</summary>

##
[2.25.0](google-cloud-iam-v2.24.1...google-cloud-iam-v2.25.0)
(2026-08-21)


### Features

* update googleapis and regenerate
([#18087](#18087))
([db1622a](db1622a))
</details>

<details><summary>google-cloud-logging: 3.16.3</summary>

##
[3.16.3](google-cloud-logging-v3.16.2...google-cloud-logging-v3.16.3)
(2026-08-21)


### Documentation

* **handwritten:** centralize CONTRIBUTING.rst pointers
([#17642](#17642))
([23b9499](23b9499))
</details>

<details><summary>google-cloud-monitoring-dashboards: 3.0.0</summary>

##
[3.0.0](google-cloud-monitoring-dashboards-v2.22.0...google-cloud-monitoring-dashboards-v3.0.0)
(2026-08-21)


### ⚠ BREAKING CHANGES

* Remove erroneous google/monitoring/dashboard clients
([#18165](#18165))

### Bug Fixes

* Remove erroneous google/monitoring/dashboard clients
([#18165](#18165))
([fb0c1b9](fb0c1b9))
</details>

<details><summary>google-cloud-ndb: 2.6.0</summary>

##
[2.6.0](google-cloud-ndb-v2.5.1...google-cloud-ndb-v2.6.0)
(2026-08-21)


### Features

* check python and dependency versions in bigquery and ndb
([#18075](#18075))
([62ff6f3](62ff6f3))


### Bug Fixes

* **ndb:** avoid unbound lock in delete callback
([#17969](#17969))
([c513b39](c513b39))
* **ndb:** use the single-argument generator.throw() signature
([#18159](#18159))
([dfb0e36](dfb0e36))


### Documentation

* **handwritten:** centralize CONTRIBUTING.rst pointers
([#17642](#17642))
([23b9499](23b9499))
</details>

<details><summary>google-cloud-oracledatabase: 0.6.2</summary>

##
[0.6.2](google-cloud-oracledatabase-v0.6.1...google-cloud-oracledatabase-v0.6.2)
(2026-08-21)


### Features

* update googleapis and regenerate
([#18087](#18087))
([db1622a](db1622a))
</details>

<details><summary>google-cloud-pubsub: 2.39.2</summary>

##
[2.39.2](google-cloud-pubsub-v2.39.1...google-cloud-pubsub-v2.39.2)
(2026-08-21)


### Documentation

* **handwritten:** centralize CONTRIBUTING.rst pointers
([#17642](#17642))
([23b9499](23b9499))
</details>

<details><summary>google-cloud-recaptcha-enterprise: 1.33.0</summary>

##
[1.33.0](google-cloud-recaptcha-enterprise-v1.32.0...google-cloud-recaptcha-enterprise-v1.33.0)
(2026-08-21)


### Features

* update googleapis and regenerate
([