shahar1 opened a new pull request, #70505:
URL: https://github.com/apache/airflow/pull/70505
related: #70296, #70347, #70297
## Human Summary
As it turns out, the check I've introduced in #70297 might have been too
strict, and we should allow some specific checks to still run in the
constructor. This PR relaxes the requirements and removes false positives
(according to the new definition) from the exemptions list.
Created a separate issue (#70503) to track reverts.
## AI Summary
<details><summary>Click here</summary>
`validate-operators-init` flags every read of a template-field parameter in
`__init__`. That is right for reads of the *value*, but wrong for reads of
*provision* — "did the author pass this argument?" — which is what
mutually-exclusive-argument checks ask.
The constructor is in fact the only place that can answer it. With
`render_template_as_native_obj=True` a provided field renders to `None`, so the
same check in `execute()` reports a supplied argument as missing. Forcing the
move also turns a static authoring mistake into a per-task-instance runtime
failure, and — because a rendered value can legitimately be falsy — invites
truthiness tests that silently accept conflicting arguments.
This adds one sanctioned pattern: `field is None` / `field is not None` on a
template-field parameter (or `self.<field>`) is allowed in `__init__`.
Everything else — truthiness, `in`, `.startswith`, `isinstance`,
transformations — stays flagged.
**Measured against the burn-down.** Replaying both checkers over every
exemption entry ever removed (31 PRs, 48 entries): **8 entries across 5 PRs**
would have needed no operator code change at all — #70341, #70338, #70348,
#70392, #70326 moved pure `is None` exclusivity checks into `execute()`
verbatim. Two cost more than churn: #70348 broke the Rendered Templates view
and needed follow-up #70373, and #70326 made a released operator argument
required. Five currently-listed entries clear with no code change and are
removed here; two of them are already claimed by contributors on #70296.
The remaining 40 entries stay flagged, correctly — they are genuine value
reads (`ruleset.strip()`, `isinstance(mongo_query, list)`, `source not in
SUPPORTED_SOURCES`).
**Second half of the change:** template-field assignments are now walked
recursively. Sanctioning the `is None` read would otherwise let `if field is
None: self.field = derive(other)` through, since the assignment check only
looked at top-level statements. That also closes a pre-existing hole with an
unrelated guard.
</details>
<details><summary>Testing Done</summary>
- `scripts/tests/ci/prek/test_validate_operators_init.py`: 35 passed. 8 of
the 10 new/changed cases fail against the pre-change checker; the 2 that don't
are guards against over-sanctioning (truthiness and `foo.get('x') is None` must
stay flagged).
- Hook run over all 541 files matching its `files:` regex: exit 0, no stale
exemptions.
- `prek run --from-ref main --stage pre-commit`: clean (includes mypy for
scripts).
</details>
<details><summary>Reviewer note: reconciling merged precedent</summary>
Five merged burn-down PRs moved pure provision checks into `execute()` and
left comments and regression tests asserting that placement. Nothing breaks —
the new rule permits `is None` in `__init__`, it does not require it — but
those files now demonstrate the pattern the docs discourage, and contributors
on #70296 learn the rule by reading them. Reverting them is tracked separately
so this PR stays reviewable.
</details>
No newsfragment: prek hook, contributing docs, and a clarification to an
existing limitations section. Not user-facing behaviour.
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — Claude Code (Opus 5)
Generated-by: Claude Code (Opus 5) following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]