`ImportChangesRule` raises false positives
See original GitHub issueApache Airflow version: 1.10.14, apache-airflow-upgrade-check==1.1.0
Kubernetes version (if you are using kubernetes) (use kubectl version
):
Environment:
- Cloud provider or hardware configuration: on-premise Linux server
- OS (e.g. from /etc/os-release): RHEL 7
- Kernel (e.g.
uname -a
): - Install tools:
- Others:
What happened:
Running airflow upgrade_check
gives a series of false positives for the import check rule. For example:
('Using `airflow.contrib.hooks.sftp_hook.SFTPHook` should be replaced by '
'`airflow.providers.sftp.hooks.sftp.SFTPHook`. Affected file: '
'/airflow/dags/std_wsljobs_dags/hccmodel_dag.py')
However, this import has actually already been updated in the indicated file, and when viewing the code using the “Code” button in the Airflow UI it shows the updated path.
What you expected to happen:
That this file would not be flagged by the ImportChangesRule.
How to reproduce it:
Run airflow upgrade_check
with a DAG file containing one of the classes whose import path changed.
Anything else we need to know:
I believe the culprit is this section from the ImportChangesRule:
@staticmethod
def _check_file(file_path):
problems = []
providers = set()
with open(file_path, "r") as file:
content = file.read()
for change in ImportChangesRule.ALL_CHANGES:
if change.old_class in content:
problems.append(change.info(file_path))
if change.providers_package:
providers.add(change.providers_package)
return problems, providers
It is only checking the the old_class
is present, not the old_path
. The if statement should read: if change.old_path in content:
. If I make this change in the source file, I receive zero problems back instead of 39.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:7 (3 by maintainers)
Yes this did it. Thank you!!
Get Outlookhttps://aka.ms/qtex0l for iOS
From: eladkal @.> Sent: Thursday, April 1, 2021 6:04:31 AM To: apache/airflow @.> Cc: James Colvin @.>; Mention @.> Subject: Re: [apache/airflow]
ImportChangesRule
raises false positives (#13570)@yergihttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fyergi&data=04|01||5179bc931f7144f02fd408d8f4f58b9f|84df9e7fe9f640afb435aaaaaaaaaaaa|1|0|637528682744009278|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D|1000&sdata=hMtTPDI7UuIOZLY3c1gekiqWA5Xy211Igc%2B%2FhM3AjyE%3D&reserved=0 were you able to verify ?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fapache%2Fairflow%2Fissues%2F13570%23issuecomment-811801612&data=04|01||5179bc931f7144f02fd408d8f4f58b9f|84df9e7fe9f640afb435aaaaaaaaaaaa|1|0|637528682744019264|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D|1000&sdata=S1dgvNuRhzh6sv9DLr0xSQnDGBKiGEq290Rbkkv9kuY%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FABZIHL7TVZ7LZNURQQ6PTETTGRAK7ANCNFSM4V2VZH7A&data=04|01||5179bc931f7144f02fd408d8f4f58b9f|84df9e7fe9f640afb435aaaaaaaaaaaa|1|0|637528682744019264|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D|1000&sdata=BtvjudxtQ4A1P82G1KIwAHH7lrEblGu26Pbjw4njiM8%3D&reserved=0.
Yes, I just created this PR. It’s my first time ever contributing to an open-source project, so please be gentle. 😄