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

Add CustomOperatorUsesMetaclassRule (#11038) #11391

Closed
wants to merge 1 commit into from

Conversation

hweecat
Copy link

@hweecat hweecat commented Oct 10, 2020

closes: #11038
related: #8765

Added CustomOperatorUsesMetaclassRule which corresponds to

BaseOperator uses metaclass

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.

@boring-cyborg
Copy link

boring-cyborg bot commented Oct 10, 2020

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)
Here are some useful points:

  • Pay attention to the quality of your code (flake8, pylint and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it’s a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@turbaszek turbaszek added the area:upgrade Facilitating migration to a newer version of Airflow label Oct 10, 2020
If your custom operator uses different metaclass then you will have to adjust it."""

def check(self):
if not isinstance(BaseOperator, BaseOperatorMeta):
Copy link
Member

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?

Copy link
Member

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.

@@ -423,8 +423,6 @@ def collect_dags(

dag_folder = correct_maybe_zipped(dag_folder)

dags_by_name = {}
Copy link
Member

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?

@@ -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)
Copy link
Member

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?

@turbaszek

This comment has been minimized.

@turbaszek turbaszek changed the base branch from v1-10-test to v1-10-stable November 3, 2020 10:29
@turbaszek
Copy link
Member

@hweecat I cleaned up the PR. Would you mind taking look at the comments from me and @mik-laj ?

@ashb
Copy link
Member

ashb commented Nov 28, 2020

Done in #12629, sorry.

@ashb ashb closed this Nov 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:upgrade Facilitating migration to a newer version of Airflow
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create CustomOperatorUsesMetaclassRule to ease upgrade to Airflow 2.0
4 participants