Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(AIR302): check whether removed context key "conf" is access through context.get(...) #15240

Closed
wants to merge 1 commit into from

Conversation

Lee-W
Copy link
Contributor

@Lee-W Lee-W commented Jan 3, 2025

Summary

context key conf is removed in Airflow3. This PR handle the case that these keys are accessed through context.get(...)

e.g.,

@task
def func(**context):
    context.get("conf")

@task()
def func(**context):
    context.get("conf")

Test Plan

A test fixture is included in the PR.

@Lee-W
Copy link
Contributor Author

Lee-W commented Jan 3, 2025

This PR also adds a utility function and works as an example to check whether this kind of access is from taskflow. for #15144

@Lee-W
Copy link
Contributor Author

Lee-W commented Jan 3, 2025

@sunank200 As I'll be out traveling for the following week and will have almost no access to laptop, if there're comments to be resolved, please feel free to push to this branch directly and this PR should help #15144 moving forward as well.

Copy link
Contributor

github-actions bot commented Jan 3, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@Lee-W
Copy link
Contributor Author

Lee-W commented Jan 3, 2025

I'm not able to finish the python_callable part in time but that part should be checked as well as discussed in #15144 (comment)

return;
};

// Ensure the method called is `context`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Ensure the method called is `context`
// Ensure the method called is on `context`

/// print("access invalid key", context.get("conf"))
/// ```
fn check_context_get(checker: &mut Checker, call_expr: &ExprCall) {
const REMOVED_CONTEXT_KEYS: [&str; 1] = ["conf"];
Copy link
Member

Choose a reason for hiding this comment

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

How many arguments are you planning to deprecate for this to be a list?

Copy link
Member

Choose a reason for hiding this comment

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

I think there are multiple as stated in this PR description: #15144 (comment)

@MichaReiser
Copy link
Member

As I'll be out traveling for the following week and will have almost no access to laptop,

Safe and good travels! Enjoy your time without a laptop ;)

/// def access_invalid_key_task_out_of_dag(**context):
/// print("access invalid key", context.get("conf"))
/// ```
fn is_taskflow(checker: &mut Checker) -> bool {
Copy link
Member

Choose a reason for hiding this comment

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

We can possible make this generic as I suspect it's going to be used for other decorators as well. Ignore if it's not going to be used for any other decorators other than @task.

fn is_decorated_with(checker: &mut Checker, decorator: &str) -> bool {
    let mut parents = checker.semantic().current_statements();
    if let Some(Stmt::FunctionDef(StmtFunctionDef { decorator_list, .. })) =
        parents.find(|stmt| stmt.is_function_def_stmt())
    {
        for decorator in decorator_list {
            if checker
                .semantic()
                .resolve_qualified_name(map_callable(&decorator.expression))
                .is_some_and(|qualified_name| {
                    matches!(qualified_name.segments(), ["airflow", "decorators", decorator])
                })
            {
                return true;
            }
        }
    }
    false
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@task is probably the only case I can think of for now 🤔 I can do the refactoring once we have another case in the future

@dhruvmanila dhruvmanila added rule Implementing or modifying a lint rule preview Related to preview mode features labels Jan 6, 2025
@sunank200
Copy link

@Lee-W I have made the generic change here: #15144

@dhruvmanila
Copy link
Member

@sunank200 This PR and the one that you've opened (#15144) seems very familiar. Does your PR supersedes this? If not, can / should they be merged?

@sunank200
Copy link

@dhruvmanila this PR #15144 supersedes this. We could keep #15144. I can make @Lee-W coauthor on my PR.

@dhruvmanila
Copy link
Member

Sounds good @sunank200, thanks. I'll close this PR then.

@dhruvmanila dhruvmanila closed this Jan 8, 2025
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.

4 participants