Skip to content

Fix GcpBodyFieldValidator warning on valid version-specific fields - #74930

Merged
shahar1 merged 2 commits into
apache:mainfrom
udsy19:fix/gcp-field-validator-api-version-warning
Nov 8, 2026
Merged

shahar1 merged 2 commits into
apache:mainfrom
udsy19:fix/gcp-field-validator-api-version-warning

Conversation

@udsy19

@udsy19 udsy19 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Why

GcpBodyFieldValidator.validate() emits a spurious warning for valid, applicable body fields.

The post-validation check that reports body fields "is in the body, but is not specified in the validation specification" builds its set of known field names with an inverted api_version filter:

all_field_names = {
    spec["name"]
    for spec in self._validation_specs
    if spec.get("type") != "union" and spec.get("api_version") != self._api_version
}

A non-union field whose spec api_version equals the validator's api_version is a valid, applicable field — _validate_field only skips a field when its api_version differs (if required_api_version and required_api_version != self._api_version: return False). The != comparison excluded exactly those applicable fields from all_field_names, so a correct, spec-defined, successfully validated field present in the body produced the spurious warning. The same inverted filter was applied to union-nested field names.

Users of GCP operators that rely on API-version-tagged body fields see misleading warnings for perfectly valid request fields.

What

Include a field whenever it has no api_version or its api_version matches the validator's — mirroring _validate_field's own applicability rule — for both the top-level and union-nested comprehensions. The common no-api_version case is unchanged.

Tests

Two parametrized tests in providers/google/tests/unit/google/cloud/utils/test_field_validator.py (top-level and union-nested field) cover both directions: a field tagged with the validator's api_version no longer warns, and a field tagged with a different api_version now warns. They patch the validator's logger rather than asserting on caplog.text. With the source reverted, all 4 cases fail; with the fix, all 4 pass.

The post-validation check that reports body fields "not specified in the
validation specification" built its set of known field names with an
inverted api_version filter:

    if spec.get("type") != "union" and spec.get("api_version") != self._api_version

A non-union field whose spec ``api_version`` equals the validator's own
``api_version`` is a valid, applicable field (``_validate_field`` only
skips a field when its ``api_version`` differs). The ``!=`` comparison
excluded exactly those applicable fields from ``all_field_names``, so a
correct, spec-defined, successfully validated field present in the body
produced a spurious "field is in the body, but is not specified in the
validation specification" warning. The same inverted filter was applied
to union-nested field names.

Include a field whenever it has no ``api_version`` or its ``api_version``
matches the validator's, so version-specific fields validated for the
current API version no longer warn, while fields that belong to a
different API version still do (as the warning text intends).

Signed-off-by: Udaya Tejas <udayatejas2004@gmail.com>
@udsy19
udsy19 requested a review from shahar1 as a code owner October 17, 2026 18:39
@boring-cyborg boring-cyborg Bot added area:providers provider:google Google (including GCP) related issues labels Oct 17, 2026
@spacexm406-web

Copy link
Copy Markdown

Improve

@shahar1 shahar1 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.

The fix is correct: validate() now uses the same applicability rule as _validate_field(), and I confirmed both new tests fail on main and pass here. Two test-side points below; the main one is that the opposite case (a field for a different API version now warns) is a behaviour change without a test.

Smaller observations

  • See inline comments on providers/google/tests/unit/google/cloud/utils/test_field_validator.py:332, providers/google/src/airflow/providers/google/cloud/utils/field_validator.py:441.

This review was drafted by an AI-assisted tool and
confirmed by an Apache Airflow maintainer. The findings
below are observations, not blockers; an Apache Airflow
maintainer — a real person — will take the next look at the
PR. If you think a finding is mis-applied, please reply on
the PR and a maintainer will weigh in.

More on how Apache Airflow handles maintainer review:
Contributing guide.

Cover both directions of the api_version filter change: a field tagged
with the validator's api_version no longer warns, and a field tagged with
a different api_version now does. Patch the validator's logger instead of
asserting on caplog.text, per review.

Signed-off-by: Udaya Tejas <udayatejas2004@gmail.com>
Generated-by: Claude Code following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)

@olegkachur-e olegkachur-e 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.

Looks good, thank you! (please address the comment)

@shahar1
shahar1 merged commit 47d0c64 into apache:main Nov 8, 2026
88 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers provider:google Google (including GCP) related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants