Skip to content

Added static check for conn-fields defined in provider.yaml#69473

Merged
dabla merged 3 commits into
apache:mainfrom
dabla:feature/add-static-check-conn-fields-provider-yaml
Jul 9, 2026
Merged

Added static check for conn-fields defined in provider.yaml#69473
dabla merged 3 commits into
apache:mainfrom
dabla:feature/add-static-check-conn-fields-provider-yaml

Conversation

@dabla

@dabla dabla commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Added static check for conn-fields defined in provider.yaml to make sure those correspond with the ones defined in the get_connection_form_widgets method of the corresponding hook.

Add static check: validate conn-fields in provider.yaml against get_connection_form_widgets()

Background

Airflow's connection UI has two layers:

  • Legacy Flask UI — driven by get_connection_form_widgets() on each Hook class.
  • New React UI — driven by the conn-fields mapping in provider.yaml (and the generated get_provider_info.py).

An existing static check already works in one direction: if a field is declared in provider.yaml conn-fields but absent from get_connection_form_widgets(), it is automatically added to the hook.

What this PR adds

This PR adds the reverse check: fields declared in provider.yaml conn-fields must exist in the corresponding hook's get_connection_form_widgets().

In other words — conn-fields must be a valid subset of the hook's form widgets. It is intentionally not required to be an identical set: some Flask form fields may be deliberately omitted from the new React UI.

The check:

  1. Imports the hook class referenced in each connection-types entry.
  2. Skips the entry silently when the hook cannot be imported (optional provider dependencies), does not override get_connection_form_widgets(), or has no conn-fields declared (the new UI intentionally exposes no custom fields for that connection type).
  3. Reports an error when a key present in conn-fields is not found in get_connection_form_widgets() — those are stale or mistyped field names that the React UI would try to render but the hook doesn't know about.

Error example

Mismatch between `conn-fields` in providers/my_provider/provider.yaml and
`airflow.providers.my_provider.hooks.my_hook.MyHook.get_connection_form_widgets()`
for connection-type 'my_conn_type':
  Fields in provider.yaml conn-fields but NOT in get_connection_form_widgets(): stale_field
How to fix it: Remove the stale key(s) from conn-fields in provider.yaml.

Files changed

File Change
scripts/ci/prek/check_provider_conn_fields.py New validation helpers (pure Python, no third-party deps, unit-testable outside Breeze)
scripts/in_container/run_provider_yaml_files_check.py Wires the new check into the existing provider YAML validation run
scripts/tests/ci/prek/test_check_conn_fields_match_form_widgets.py Unit tests covering all branches

Was generative AI tooling used to co-author this PR?
  • [ x ] Yes (please specify the tool below)

Claude Sonnet 4.6 (GitHub Copilot CLI)


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@dabla
dabla force-pushed the feature/add-static-check-conn-fields-provider-yaml branch from dcc3524 to 1f8b257 Compare July 6, 2026 13:43
@dabla
dabla force-pushed the feature/add-static-check-conn-fields-provider-yaml branch 6 times, most recently from 92524b0 to 0057094 Compare July 7, 2026 08:33
@dabla
dabla requested a review from shahar1 as a code owner July 7, 2026 10:24
… to make sure those correspond with the ones defined in the get_connection_form_widgets method of the corresponding hook
@dabla
dabla force-pushed the feature/add-static-check-conn-fields-provider-yaml branch from 7345dc0 to ece3e32 Compare July 7, 2026 13:00

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dabla — nice, well-factored check: the pure helpers in check_provider_conn_fields.py are cleanly separated from the import glue and thoroughly unit-tested, and the subset semantics (React conn-fields ⊆ Flask form widgets) are the right call.

One thing worth flagging on process: the check-provider-yaml-valid prek hook only triggers on provider.yaml changes, so this PR's own CI never actually runs the new check against real providers — only the mocked unit tests ran here. I reproduced the real check locally against the full set of providers that declare conn-fields (installed all 33, ran _get_widget_keys + the subset comparison): 50 connection-type entries validated, 0 stale keys, so it passes cleanly against current main and won't start failing unrelated PRs. Approving on that basis. It might still be worth running prek run check-provider-yaml-valid --all-files once before merge as a belt-and-suspenders check in the full Breeze environment (a handful of hooks — AzureBatchHook etc. — I could only skip locally on optional-dep import errors).

Two non-blocking nits inline (docstring correctness + a coverage note). Neither blocks merge.


This review was drafted with AI assistance (Claude Code, Opus 4.8) and may contain mistakes; an Apache Airflow maintainer (@potiuk) has read and confirmed it before posting. For what the project considers a maintainer review, see the contributing guide.

Drafted-by: Claude Code (Opus 4.8); reviewed by @potiuk before posting

Comment thread scripts/in_container/run_provider_yaml_files_check.py Outdated
Comment thread scripts/in_container/run_provider_yaml_files_check.py
@dabla
dabla merged commit 53de1c1 into apache:main Jul 9, 2026
153 checks passed
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-3-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
v3-3-test PR Link

@dabla
dabla deleted the feature/add-static-check-conn-fields-provider-yaml branch July 9, 2026 12:06
potiuk added a commit that referenced this pull request Jul 13, 2026
…ml (#69473) (#69653)

* refactor: Added static check for conn-fields defined in provider.yaml to make sure those correspond with the ones defined in the get_connection_form_widgets method of the corresponding hook

* Update scripts/in_container/run_provider_yaml_files_check.py



* refactor: Updated comment in _get_widget_keys method

---------
(cherry picked from commit 53de1c1)

Co-authored-by: David Blain <info@dabla.be>
Co-authored-by: Jarek Potiuk <jarek@potiuk.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants