dkranchii opened a new pull request, #67300:
URL: https://github.com/apache/airflow/pull/67300

   ## Summary
   
   Follow-up to #66960. Extends the static check 
`scripts/ci/prek/check_trigger_serialize_init.py` to resolve trigger 
`serialize()` methods built via a local variable — the most common pattern that 
the original check explicitly skipped to avoid false positives. Also adds the 
first test file for the hook.
   
   Triggers like `WorkflowTrigger` and `DagStateTrigger` (standard provider) 
that were silently skipped before this change are now actually validated.
   
   ## What's resolved
   
   The new resolver handles this shape:
   
   ```python
   def serialize(self):
       data = {"a": self.a}                       # literal-dict init (Assign 
or AnnAssign)
       data["b"] = self.b                         # subscript assign with 
string-constant key
       data.update({"c": self.c, "d": self.d})    # .update() with a 
literal-dict argument
       if cond:
           data["e"] = self.e                     # conditional branches are 
unioned
       return "<classpath>", data
   ```
   
   All key-adding paths (including conditional branches) are unioned — a key 
that *could* appear in the output is treated as preserved on the round-trip.
   
   ## Conservative-skip preserved
   
   The check still returns `None` (skip rather than guess) on every dynamic 
shape it cannot prove statically. New skip cases:
   
   - Reassignment of the return variable to a non-dict expression
   - Multiple literal-dict initializations of the same variable
   - Subscript assignments with a non-string-constant key
   - `.update()` with a non-literal-dict argument or with kwargs
   - Variable never initialized in the function
   
   Plus a small structural improvement: return statements are now collected via 
a new `_walk_skip_nested` helper, so a `return` inside a nested helper function 
inside `serialize()` no longer trips the "exactly one return" check (it never 
was a real second return for `serialize`).
   
   ## Verification
   
   - Static check on `providers/` tree: exit 0 — **no false positives** 
introduced.
   - `WorkflowTrigger` (11 init params) and `DagStateTrigger` (5 init params) 
now resolve cleanly — both were silently skipped before.
   - 19 unit tests covering both resolvers (literal-dict and 
dict-via-variable), 6 parametrized unresolvable shapes, nested-helper 
isolation, and 2 still-skipped sanity shapes — all pass.
   - Synthetic-bug test (a `WorkflowTrigger` with a deliberately-dropped param) 
is correctly flagged.
   
   ## Test plan
   
   - [ ] `uv run --project scripts pytest 
scripts/tests/ci/prek/test_check_trigger_serialize_init.py -xvs` passes
   - [ ] `prek run --from-ref upstream/main --stage pre-commit` passes
   - [ ] `prek run --from-ref upstream/main --stage manual` passes
   - [ ] Static check on providers tree (`uv run --project scripts python 
scripts/ci/prek/check_trigger_serialize_init.py`) returns 0
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — Cursor (Claude Opus 4.7)
   
   Generated-by: Cursor (Claude Opus 4.7) 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]

Reply via email to