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

Replace deprecated DummyOperator by EmptyOperator if Airflow >=2.4.0 #900

Merged
merged 2 commits into from
Mar 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions dev/dags/example_cosmos_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
from pathlib import Path

from airflow.models.dag import DAG
from airflow.operators.dummy import DummyOperator

try: # available since Airflow 2.4.0
from airflow.operators.empty import EmptyOperator
except ImportError:
from airflow.operators.dummy import DummyOperator as EmptyOperator
from airflow.utils.task_group import TaskGroup

from cosmos import DbtDag, ProfileConfig, ProjectConfig, RenderConfig
Expand All @@ -38,21 +42,21 @@


# [START custom_dbt_nodes]
# Cosmos will use this function to generate a DummyOperator task when it finds a source node, in the manifest.
# Cosmos will use this function to generate an empty task when it finds a source node, in the manifest.
# A more realistic use case could be to use an Airflow sensor to represent a source.
def convert_source(dag: DAG, task_group: TaskGroup, node: DbtNode, **kwargs):
"""
Return an instance of DummyOperator to represent a dbt "source" node.
Return an instance of a desired operator to represent a dbt "source" node.
"""
return DummyOperator(dag=dag, task_group=task_group, task_id=f"{node.name}_source")
return EmptyOperator(dag=dag, task_group=task_group, task_id=f"{node.name}_source")


# Cosmos will use this function to generate a DummyOperator task when it finds a exposure node, in the manifest.
# Cosmos will use this function to generate an empty task when it finds a exposure node, in the manifest.
def convert_exposure(dag: DAG, task_group: TaskGroup, node: DbtNode, **kwargs):
"""
Return an instance of DummyOperator to represent a dbt "exposure" node.
Return an instance of a desired operator to represent a dbt "exposure" node.
"""
return DummyOperator(dag=dag, task_group=task_group, task_id=f"{node.name}_exposure")
return EmptyOperator(dag=dag, task_group=task_group, task_id=f"{node.name}_exposure")


# Use `RenderConfig` to tell Cosmos, given a node type, how to convert a dbt node into an Airflow task or task group.
Expand Down
Loading