Skip to content

Conversation

@sjyangkevin
Copy link
Contributor

Summary

Context:
apache/airflow#41641
apache/airflow#46415

In the old signature, dttm is used by Airflow as a positional argument, so the argument name in the function declaration may not be dttm. In the new signature, however, the argument name must be ti_key (although it may be non-keyword-only; self, operator, ti_key should be considered new signature). So the deprecated signature detection rule should be exactly three positional arguments, the third one not named ti_key.

Old Signature

class MyOperatorLink(BaseOperatorLink):
    def get_link(self, operator, dttm):
        ...

New Signature

class MyOperatorLink(BaseOperatorLink):
    def get_link(self, operator, *, ti_key):
        ...

This PR extends AIR303 to detect deprecated get_link method signatures in BaseOperatorLink subclasses, which is a method definition. BaseOperatorLink is a base class can be extended by the user, and the get_link method is called by Airflow. As the way Airflow internally call this method change, we need to flag the user's implementation if the method definition is not match with the new signature (@Lee-W , please correct me if I understand it wrong, whenever you have time, thanks). The rule detects deprecated signatures where:

  1. The class inherits from BaseOperatorLink (from airflow.models or airflow.sdk)
  2. The method is named get_link
  3. There are exactly 3 positional parameters
  4. The 3rd parameter is not named as ti_key
Screenshot from 2026-01-23 22-25-34

Test Plan

The test cases are added to AIR303.py and the test snapshot is updated.

Comment on lines +55 to +60
#[derive(Clone, Debug, Eq, PartialEq)]
pub(crate) enum FunctionSignatureChange {
/// Carries a message describing the function signature change.
Message(&'static str),
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The original definition in function_signature_change_in_3.rs becomes redundant as these enum items only encapsulate a message. Therefore, combine these into a single Message item, and move it to helpers.rs. This enum will be dedicated used for AIR303, or function signature change in future version of Airflow.

#[derive(Clone, Debug, Eq, PartialEq)]
pub(crate) enum FunctionSignatureChangeType {
    /// Function signature changed to only accept keyword arguments.
    KeywordOnly { message: &'static str },
    /// Function signature changed to not accept certain positional arguments.
    PositionalArgumentChange { message: &'static str },
}


/// This is a helper function to check if the given function definition is a method
/// that inherits from a base class.
pub(crate) fn is_method_in_subclass<F>(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This helper function generalizes the function is_execute_method_inherits_from_airflow_operator defined in the removal_in_3.rs. The function is checking if a subclass of airflow's BaseOperator implements a execute function. In AIR303, we need to check if a subclass of airflow's BaseOperatorLink implements a get_link function. Therefore, this is something reusable across multiple rules. I parameterized the method name and the match condition, to reduce redundant definition for similar checks.

@astral-sh-bot
Copy link

astral-sh-bot bot commented Jan 24, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@sjyangkevin sjyangkevin force-pushed the air303-BaseOperatorLink-get_link branch from 2c7f7d2 to 78dccc5 Compare January 28, 2026 04:56
Comment on lines +117 to +141
let is_valid_signature = match positional_count {
// check valid signature `def get_link(self, operator, *, ti_key)`
2 => parameters
.kwonlyargs
.iter()
.any(|p| p.name().as_str() == "ti_key"),
// check valid signature `def get_link(self, operator, ti_key)`
3 => parameters
.posonlyargs
.iter()
.chain(parameters.args.iter())
.nth(2)
.is_some_and(|p| p.name().as_str() == "ti_key"),
_ => false,
};

if !is_valid_signature {
checker.report_diagnostic(
Airflow3IncompatibleFunctionSignature {
function_name: "get_link".to_string(),
change: FunctionSignatureChange::Message(
"Use `def get_link(self, operator, *, ti_key)` or `def get_link(self, operator, ti_key)` as the method signature.",
),
},
function_def.name.range(),
Copy link
Contributor Author

@sjyangkevin sjyangkevin Jan 28, 2026

Choose a reason for hiding this comment

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

updated the logic to check for valid signature pattern, which is either def get_link(self, operator, *, ti_key) or ``def get_link(self, operator, ti_key)`, and the diagnostic will be raised when the method signature is evaluated to invalid.

The name of the first two positional parameters doesn't matter for the rule. If there are 2 positional parameters (i.e., self, operator), check if the keyword-only parameter is named ti_key. If there are 3 positional parameters, check if the third one is named ti_key.

The message and test cases are updated accordingly.

@sjyangkevin sjyangkevin requested a review from Lee-W January 28, 2026 05:04
@ntBre ntBre added rule Implementing or modifying a lint rule preview Related to preview mode features labels Jan 28, 2026
let positional_count = parameters.posonlyargs.len() + parameters.args.len();

let is_valid_signature = match positional_count {
// check valid signature `def get_link(self, operator, *, ti_key)`
Copy link
Contributor

Choose a reason for hiding this comment

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

what would happen if we use def get_link(self, operator, ti_key)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case, I think we have 3 positional parameters, and it will not match the first condition which check if the number of positional parameters is 2. It will proceed to the next condition and check if there are 3 positional parameters and iterate through it see if the 3rd one is named ti_key. I’ve added a test case for this but will also do a double check. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview Related to preview mode features rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants