-
Notifications
You must be signed in to change notification settings - Fork 13.8k
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
Add CustomOperatorUsesMetaclassRule (#11038) #11391
Conversation
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst)
|
If your custom operator uses different metaclass then you will have to adjust it.""" | ||
|
||
def check(self): | ||
if not isinstance(BaseOperator, BaseOperatorMeta): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid that BaseOperatorMeta
is not available in Airflow 1.10.X so we cannot use it like that.
Approaches that comes to my mind:
- create a dagbag of users DAGs and then iterate over the tasks and check if any of them is using metaclass (any of them as Python allow users using only a single metaclass)
- find all import statements in users DAGs and analyze those classes that inherit from
BaseOperator
We can also just rise this as a warning without any check as using metaclass is rather an edge case imho. @kaxil @mik-laj what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think this is an edge case. Many users use the ABC of the metaclass. This may not be common in this project, but people who know Jave (previously used Spark) and then started writing operators may be overusing abstract classes.
airflow/models/dagbag.py
Outdated
@@ -423,8 +423,6 @@ def collect_dags( | |||
|
|||
dag_folder = correct_maybe_zipped(dag_folder) | |||
|
|||
dags_by_name = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you tell more about it?
airflow/models/skipmixin.py
Outdated
@@ -122,7 +121,8 @@ def skip_all_except( | |||
""" | |||
self.log.info("Following branch %s", branch_task_ids) | |||
if isinstance(branch_task_ids, six.string_types): | |||
branch_task_ids = [branch_task_ids] | |||
branch_task_ids = {branch_task_ids} | |||
branch_task_ids = set(branch_task_ids) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you tell more about it?
This comment has been minimized.
This comment has been minimized.
abcb626
to
57afe5f
Compare
Done in #12629, sorry. |
closes: #11038
related: #8765
Added CustomOperatorUsesMetaclassRule which corresponds to
entry in UPDATING.md. This rule should allow users to check if their current configuration needs any adjusting
before migration to Airflow 2.0.
Read the Pull Request Guidelines for more information.
In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.