|
32 | 32 | from airflow import __version__ as AIRFLOW_VERSION
|
33 | 33 |
|
34 | 34 | # TODO: move this maybe to Airflow's logic?
|
35 |
| -from airflow.models import BaseOperator, DagRun, TaskReschedule |
| 35 | +from airflow.models import DagRun, TaskReschedule |
36 | 36 | from airflow.providers.openlineage import (
|
37 | 37 | __version__ as OPENLINEAGE_PROVIDER_VERSION,
|
38 | 38 | conf,
|
|
59 | 59 | if not AIRFLOW_V_3_0_PLUS:
|
60 | 60 | from airflow.utils.session import NEW_SESSION, provide_session
|
61 | 61 |
|
62 |
| -try: |
63 |
| - from airflow.sdk import BaseOperator as SdkBaseOperator |
64 |
| -except ImportError: |
65 |
| - SdkBaseOperator = BaseOperator # type: ignore[misc] |
66 |
| - |
67 | 62 | if TYPE_CHECKING:
|
68 | 63 | from openlineage.client.event_v2 import Dataset as OpenLineageDataset
|
69 | 64 | from openlineage.client.facet_v2 import RunFacet, processing_engine_run
|
70 | 65 |
|
71 | 66 | from airflow.models import TaskInstance
|
72 | 67 | from airflow.providers.common.compat.assets import Asset
|
73 | 68 | from airflow.sdk import DAG
|
| 69 | + from airflow.sdk.bases.operator import BaseOperator |
74 | 70 | from airflow.sdk.definitions.mappedoperator import MappedOperator
|
75 | 71 | from airflow.sdk.execution_time.secrets_masker import (
|
76 | 72 | Redactable,
|
|
82 | 78 | else:
|
83 | 79 | try:
|
84 | 80 | from airflow.sdk import DAG
|
| 81 | + from airflow.sdk.bases.operator import BaseOperator |
85 | 82 | from airflow.sdk.definitions.mappedoperator import MappedOperator
|
86 | 83 | except ImportError:
|
87 |
| - from airflow.models import DAG, MappedOperator |
| 84 | + from airflow.models import DAG, BaseOperator, MappedOperator |
88 | 85 |
|
89 | 86 | try:
|
90 | 87 | from airflow.providers.common.compat.assets import Asset
|
@@ -119,7 +116,7 @@ def try_import_from_string(string: str) -> Any:
|
119 | 116 | return import_string(string)
|
120 | 117 |
|
121 | 118 |
|
122 |
| -def get_operator_class(task: BaseOperator | SdkBaseOperator) -> type: |
| 119 | +def get_operator_class(task: BaseOperator) -> type: |
123 | 120 | if task.__class__.__name__ in ("DecoratedMappedOperator", "MappedOperator"):
|
124 | 121 | return task.operator_class
|
125 | 122 | return task.__class__
|
@@ -203,25 +200,25 @@ def get_user_provided_run_facets(ti: TaskInstance, ti_state: TaskInstanceState)
|
203 | 200 | return custom_facets
|
204 | 201 |
|
205 | 202 |
|
206 |
| -def get_fully_qualified_class_name(operator: BaseOperator | MappedOperator | SdkBaseOperator) -> str: |
| 203 | +def get_fully_qualified_class_name(operator: BaseOperator | MappedOperator) -> str: |
207 | 204 | if isinstance(operator, (MappedOperator, SerializedBaseOperator)):
|
208 | 205 | # as in airflow.api_connexion.schemas.common_schema.ClassReferenceSchema
|
209 | 206 | return operator._task_module + "." + operator._task_type # type: ignore
|
210 | 207 | op_class = get_operator_class(operator)
|
211 | 208 | return op_class.__module__ + "." + op_class.__name__
|
212 | 209 |
|
213 | 210 |
|
214 |
| -def is_operator_disabled(operator: BaseOperator | MappedOperator | SdkBaseOperator) -> bool: |
| 211 | +def is_operator_disabled(operator: BaseOperator | MappedOperator) -> bool: |
215 | 212 | return get_fully_qualified_class_name(operator) in conf.disabled_operators()
|
216 | 213 |
|
217 | 214 |
|
218 |
| -def is_selective_lineage_enabled(obj: DAG | BaseOperator | MappedOperator | SdkBaseOperator) -> bool: |
| 215 | +def is_selective_lineage_enabled(obj: DAG | BaseOperator | MappedOperator) -> bool: |
219 | 216 | """If selective enable is active check if DAG or Task is enabled to emit events."""
|
220 | 217 | if not conf.selective_enable():
|
221 | 218 | return True
|
222 | 219 | if isinstance(obj, DAG):
|
223 | 220 | return is_dag_lineage_enabled(obj)
|
224 |
| - if isinstance(obj, (BaseOperator, MappedOperator, SdkBaseOperator)): |
| 221 | + if isinstance(obj, (BaseOperator, MappedOperator)): |
225 | 222 | return is_task_lineage_enabled(obj)
|
226 | 223 | raise TypeError("is_selective_lineage_enabled can only be used on DAG or Operator objects")
|
227 | 224 |
|
|
0 commit comments