Resolve dict-via-variable trigger serialize() in static check#67300
Open
dkranchii wants to merge 1 commit into
Open
Resolve dict-via-variable trigger serialize() in static check#67300dkranchii wants to merge 1 commit into
dkranchii wants to merge 1 commit into
Conversation
Extends the trigger __init__/serialize() consistency check to handle serialize() methods that build their return dict via a local variable (literal-dict init, optional subscript assignments, and .update() with literal-dict args, with conditional branches unioned). Triggers like WorkflowTrigger and DagStateTrigger that were previously silently skipped are now actually validated. Also adds the first test file for this hook.
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #66960. Extends the static check
scripts/ci/prek/check_trigger_serialize_init.pyto resolve triggerserialize()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
WorkflowTriggerandDagStateTrigger(standard provider) that were silently skipped before this change are now actually validated.What's resolved
The new resolver handles this shape:
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:.update()with a non-literal-dict argument or with kwargsPlus a small structural improvement: return statements are now collected via a new
_walk_skip_nestedhelper, so areturninside a nested helper function insideserialize()no longer trips the "exactly one return" check (it never was a real second return forserialize).Verification
providers/tree: exit 0 — no false positives introduced.WorkflowTrigger(11 init params) andDagStateTrigger(5 init params) now resolve cleanly — both were silently skipped before.WorkflowTriggerwith a deliberately-dropped param) is correctly flagged.Test plan
uv run --project scripts pytest scripts/tests/ci/prek/test_check_trigger_serialize_init.py -xvspassesprek run --from-ref upstream/main --stage pre-commitpassesprek run --from-ref upstream/main --stage manualpassesuv run --project scripts python scripts/ci/prek/check_trigger_serialize_init.py) returns 0Was generative AI tooling used to co-author this PR?
Generated-by: Cursor (Claude Opus 4.7) following the guidelines