Skip to content

Commit 1a610af

Browse files
authored
Migrate dbt.cloud provider to common.compat (apache#56999)
Replace version-specific conditional imports with ``common.compat`` layer. This standardizes compatibility handling across Airflow 2.x and 3.x.
1 parent c61c9e4 commit 1a610af

File tree

5 files changed

+4
-25
lines changed

5 files changed

+4
-25
lines changed

providers/dbt/cloud/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ requires-python = ">=3.10"
5858
# After you modify the dependencies, and rebuild your Breeze CI image with ``breeze ci-image build``
5959
dependencies = [
6060
"apache-airflow>=2.10.0",
61-
"apache-airflow-providers-common-compat>=1.6.0",
61+
"apache-airflow-providers-common-compat>=1.7.4", # + TODO: bump to next version
6262
"apache-airflow-providers-http",
6363
"asgiref>=2.3.0",
6464
"aiohttp>=3.9.2",

providers/dbt/cloud/src/airflow/providers/dbt/cloud/operators/dbt.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from typing import TYPE_CHECKING, Any
2525

2626
from airflow.configuration import conf
27+
from airflow.providers.common.compat.sdk import BaseOperator, BaseOperatorLink, XCom
2728
from airflow.providers.dbt.cloud.hooks.dbt import (
2829
DbtCloudHook,
2930
DbtCloudJobRunException,
@@ -32,11 +33,6 @@
3233
)
3334
from airflow.providers.dbt.cloud.triggers.dbt import DbtCloudRunJobTrigger
3435
from airflow.providers.dbt.cloud.utils.openlineage import generate_openlineage_events_from_dbt_cloud_run
35-
from airflow.providers.dbt.cloud.version_compat import (
36-
BaseOperator,
37-
BaseOperatorLink,
38-
XCom,
39-
)
4036

4137
if TYPE_CHECKING:
4238
from airflow.providers.openlineage.extractors import OperatorLineage

providers/dbt/cloud/src/airflow/providers/dbt/cloud/sensors/dbt.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,10 @@
2222

2323
from airflow.configuration import conf
2424
from airflow.exceptions import AirflowException
25+
from airflow.providers.common.compat.sdk import BaseSensorOperator
2526
from airflow.providers.dbt.cloud.hooks.dbt import DbtCloudHook, DbtCloudJobRunException, DbtCloudJobRunStatus
2627
from airflow.providers.dbt.cloud.triggers.dbt import DbtCloudRunJobTrigger
2728
from airflow.providers.dbt.cloud.utils.openlineage import generate_openlineage_events_from_dbt_cloud_run
28-
from airflow.providers.dbt.cloud.version_compat import AIRFLOW_V_3_0_PLUS
29-
30-
if AIRFLOW_V_3_0_PLUS:
31-
from airflow.sdk import BaseSensorOperator
32-
else:
33-
from airflow.sensors.base import BaseSensorOperator # type: ignore[no-redef]
3429

3530
if TYPE_CHECKING:
3631
from airflow.providers.openlineage.extractors import OperatorLineage

providers/dbt/cloud/src/airflow/providers/dbt/cloud/version_compat.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,6 @@ def get_base_airflow_version_tuple() -> tuple[int, int, int]:
3434

3535
AIRFLOW_V_3_0_PLUS = get_base_airflow_version_tuple() >= (3, 0, 0)
3636

37-
if AIRFLOW_V_3_0_PLUS:
38-
from airflow.sdk import BaseOperator, BaseOperatorLink, BaseSensorOperator
39-
from airflow.sdk.execution_time.xcom import XCom
40-
else:
41-
from airflow.models import BaseOperator, XCom
42-
from airflow.models.baseoperatorlink import BaseOperatorLink # type: ignore[no-redef]
43-
from airflow.sensors.base import BaseSensorOperator # type: ignore[no-redef]
44-
4537
__all__ = [
4638
"AIRFLOW_V_3_0_PLUS",
47-
"BaseOperator",
48-
"BaseSensorOperator",
49-
"BaseOperatorLink",
50-
"XCom",
5139
]

providers/dbt/cloud/tests/unit/dbt/cloud/operators/test_dbt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424

2525
from airflow.exceptions import TaskDeferred
2626
from airflow.models import DAG, Connection
27+
from airflow.providers.common.compat.sdk import timezone
2728
from airflow.providers.dbt.cloud.hooks.dbt import DbtCloudHook, DbtCloudJobRunException, DbtCloudJobRunStatus
2829
from airflow.providers.dbt.cloud.operators.dbt import (
2930
DbtCloudGetJobRunArtifactOperator,
3031
DbtCloudListJobsOperator,
3132
DbtCloudRunJobOperator,
3233
)
3334
from airflow.providers.dbt.cloud.triggers.dbt import DbtCloudRunJobTrigger
34-
from airflow.utils import timezone
3535

3636
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS
3737

0 commit comments

Comments
 (0)