Repository navigation
Fix GcpBodyFieldValidator warning on valid version-specific fields - #74930
Conversation
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>
|
Improve |
shahar1
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Looks good, thank you! (please address the comment)
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_versionfilter:A non-union field whose spec
api_versionequals the validator'sapi_versionis a valid, applicable field —_validate_fieldonly skips a field when itsapi_versiondiffers (if required_api_version and required_api_version != self._api_version: return False). The!=comparison excluded exactly those applicable fields fromall_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_versionor itsapi_versionmatches the validator's — mirroring_validate_field's own applicability rule — for both the top-level and union-nested comprehensions. The common no-api_versioncase 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'sapi_versionno longer warns, and a field tagged with a differentapi_versionnow warns. They patch the validator's logger rather than asserting oncaplog.text. With the source reverted, all 4 cases fail; with the fix, all 4 pass.