Skip to content

[airflow] passing positional argument into airflow.lineage.hook.HookLineageCollector.create_asset is not allowed (AIR301)#21096

Closed
Lee-W wants to merge 2 commits into
astral-sh:mainfrom
astronomer:extend-AIR301-pos-argument
Closed

[airflow] passing positional argument into airflow.lineage.hook.HookLineageCollector.create_asset is not allowed (AIR301)#21096
Lee-W wants to merge 2 commits into
astral-sh:mainfrom
astronomer:extend-AIR301-pos-argument

Conversation

@Lee-W
Copy link
Copy Markdown
Contributor

@Lee-W Lee-W commented Oct 27, 2025

…e_asset has positional arguments

Summary

  • passing positional argument into airflow.lineage.hook.HookLineageCollector.create_asset is not allowed
    • check whether positional argument with 0 index can be found

Test Plan

update the test fixture accordingly and reorganize in the next commit

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Oct 27, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@Lee-W Lee-W force-pushed the extend-AIR301-pos-argument branch from e224675 to 4114892 Compare October 28, 2025 09:17
@Lee-W Lee-W changed the title feat(AIR301): warn if airflow.lineage.hook.HookLineageCollector.creat… [airflow] passing positional argument into airflow.lineage.hook.HookLineageCollector.create_asset is not allowed (AIR301) Oct 28, 2025
@Lee-W Lee-W marked this pull request as ready for review October 28, 2025 09:45
Copy link
Copy Markdown
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

I haven't followed the airflow PRs closely so I don't know if this is the first check for positional arguments.

Did airflow 2 allow position arguments but airflow 3 does no more?

I can see how this check is useful but it's something a type checker could catch too.

59 | hlc.create_asset("should", "be", "no", "posarg")
60 | hlc.create_asset(name="but", uri="kwargs are ok")
|
help: Calling ``HookLineageCollector.create_asset`` with positional argument should raise an error
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.

Is this the intended message you want to show to users? Shouldn't it say instead that position arguments are disallowed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Let me reword it again

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

After reading the whole message yet again, we should probably add a AIR303 for function signature change. I have another local branch working on something similar and moving this one there might be better as create_asset is not removed. Only its signature changed.

WDTY?

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.

Agree, AIR301 feels out of place for a signature change because it's not a removal

@Lee-W
Copy link
Copy Markdown
Contributor Author

Lee-W commented Oct 29, 2025

I haven't followed the airflow PRs closely so I don't know if this is the first check for positional arguments.

Yes, I think this is the first one

Did airflow 2 allow position arguments but airflow 3 does no more?

Yes.

I can see how this check is useful but it's something a type checker could catch too.

Yes, but we think it would still be helpful if these rules can also detect it here. As most of our users would be data engineers and might not care type checking that much

apache/airflow#47615 (comment)

@Lee-W Lee-W marked this pull request as draft October 29, 2025 01:24
@MichaReiser
Copy link
Copy Markdown
Member

Yes, but we think it would still be helpful if these rules can also detect it here. As most of our users would be data engineers and might not care type checking that much

Fair enough. I'd prefer a separate rule because that would also make it easier to deprecate said rule when we introduce a general-purpose rule that detects positional arguments that should have been passed as keyword arguments (which we already have in ty)

@MichaReiser
Copy link
Copy Markdown
Member

Thanks for working on this PR.

I'll close this PR as it seems stale. @Lee-W, don't hesitate to submit a new PR if you plan to get back to this.

@sjyangkevin
Copy link
Copy Markdown
Contributor

thank you @Lee-W for working on this, and thank you @MichaReiser for sharing the feedback. I discussed with @Lee-W , and I would like to pick up the work for adding this rule. As I am new to ruff, so I am still reviewing the contribution guide, and would like to start by asking some basic questions.

Create a new code AIR303

I am wondering if I need to open an issue to discuss the creation of the code AIR303 before starting the implementation. Have we decided on the naming for the new rule (e.g., detect_positional_argument, ...)?

High-level thinking on implementation

From my high-level understanding, the new code could be added to the code.rs, and then I need to create a new file under crates/ruff_linter/src/rules/airflow/rules to implement the rule, and link it with the new code. I am looking into the code change in this PR and trying to understand the process (https://docs.astral.sh/ruff/contributing/#example-adding-a-new-lint-rule) to get a deeper understanding on the details.

(Airflow, "001") => rules::airflow::rules::AirflowVariableNameTaskIdMismatch,
(Airflow, "002") => rules::airflow::rules::AirflowDagNoScheduleArgument,
(Airflow, "301") => rules::airflow::rules::Airflow3Removal,
(Airflow, "302") => rules::airflow::rules::Airflow3MovedToProvider,
(Airflow, "311") => rules::airflow::rules::Airflow3SuggestedUpdate,
(Airflow, "312") => rules::airflow::rules::Airflow3SuggestedToMoveToProvider,

Thanks,

@Lee-W
Copy link
Copy Markdown
Contributor Author

Lee-W commented Dec 15, 2025

I am wondering if I need to open an issue to discuss the creation of the code AIR303 before starting the implementation.

I think we're good? given that I didn't create an issue for this one.

Have we decided on the naming for the new rule (e.g., detect_positional_argument, ...)?

function_signature_change or something similar might be better

ntBre pushed a commit that referenced this pull request Dec 30, 2025
…okLineageCollector.create_asset` is not allowed (`AIR303`) (#22046)

## Summary

This is a follow up PR to #21096

The new code AIR303 is added for checking function signature change in
Airflow 3.0. The new rule added to AIR303 will check if positional
argument is passed into
`airflow.lineage.hook.HookLineageCollector.create_asset`. Since this
method is updated to accept only keywords argument, passing positional
argument into it is not allowed, and will raise an error. The test is
done by checking whether positional argument with 0 index can be found.

## Test Plan

A new test file is added to the fixtures for the code AIR303. Snapshot
test is updated accordingly.

<img width="1444" height="513" alt="Screenshot from 2025-12-17 20-54-48"
src="https://github.com/user-attachments/assets/bc235195-e986-4743-9bf7-bba65805fb87"
/>

<img width="981" height="433" alt="Screenshot from 2025-12-17 21-34-29"
src="https://github.com/user-attachments/assets/492db71f-58f2-40ba-ad2f-f74852fa5a6b"
/>
KotlinIsland pushed a commit to KotlinIsland/basedpython that referenced this pull request May 1, 2026
…okLineageCollector.create_asset` is not allowed (`AIR303`) (#22046)

## Summary

This is a follow up PR to astral-sh/ruff#21096

The new code AIR303 is added for checking function signature change in
Airflow 3.0. The new rule added to AIR303 will check if positional
argument is passed into
`airflow.lineage.hook.HookLineageCollector.create_asset`. Since this
method is updated to accept only keywords argument, passing positional
argument into it is not allowed, and will raise an error. The test is
done by checking whether positional argument with 0 index can be found.

## Test Plan

A new test file is added to the fixtures for the code AIR303. Snapshot
test is updated accordingly.

<img width="1444" height="513" alt="Screenshot from 2025-12-17 20-54-48"
src="https://github.com/user-attachments/assets/bc235195-e986-4743-9bf7-bba65805fb87"
/>

<img width="981" height="433" alt="Screenshot from 2025-12-17 21-34-29"
src="https://github.com/user-attachments/assets/492db71f-58f2-40ba-ad2f-f74852fa5a6b"
/>
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.

3 participants