Skip to content

KN-5: no-alias-sort-keys rule from apache/airflow#75025 with real-cod… - #7

Merged
vedntzz merged 1 commit into
mainfrom
kn-5-guard-rule
Oct 27, 2026
Merged

vedntzz merged 1 commit into
mainfrom
kn-5-guard-rule

Conversation

@vedntzz

@vedntzz vedntzz commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Summary

Adds the first guard rule, no-alias-sort-keys, encoding the decision from
apache/airflow#75025: get_dags() must not sort by state / start_date,
and the rejected fix of aliasing them onto DagRun.state /
DagRun.start_date is also blocked.

The rule flags either form inside a SortParam(...) call. The outer inside
uses stopBy: end; without it the rule silently matches nothing (verified:
removing it drops violating.py from 2 matches to 0). Direct-parent checks
use stopBy: neighbor deliberately.

Fixtures come from the real PR (base 935bac04f06a, head ac13d1d9f9e6),
trimmed to excerpts with Apache-2.0 headers. rejected_alias.py is the one
exception: constructed from the alternative described in review, and labelled
MODIFIED, not Airflow code. Fixtures are excluded from ufmt and pyright so they
stay verbatim.

This rule is intentionally specific. It's the hand-written answer key the Muse
Spark compiler will be measured against.

Test Plan

Red run first:

  • ast-grep scan --rule knack/guard/rules/no-alias-sort-keys.yml --json → Error: Cannot read rule, exit 6; all rule tests failed

Green:
Green:

  • pre_fix.py → 2 matches ("state", "start_date"); rejected_alias.py → 2; violating.py → exactly 2
  • fixed.py, legit_last_run_state.py, unrelated_state.py → 0
  • pytest → 45 passed (7 rule tests + 38 existing)
  • ufmt check knack tests → clean
  • pyright → 0 errors

Ticket

KN-5

@vedntzz
vedntzz merged commit 7e0c667 into main Oct 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant