Skip to content

Commit

Permalink
fix(providers): use version compare to decide whether to import asset
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee-W committed Nov 15, 2024
1 parent 2bc8e72 commit 158266d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions providers/src/airflow/providers/common/io/assets/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@
import urllib.parse
from typing import TYPE_CHECKING

try:
from packaging.version import Version

from airflow import __version__ as AIRFLOW_VERSION

# TODO: Remove version check block after bumpping common provider to 1.3.0
AIRFLOW_V_3_0_PLUS = Version(Version(AIRFLOW_VERSION).base_version) >= Version("3.0.0")
if AIRFLOW_V_3_0_PLUS:
from airflow.sdk.definitions.asset import Asset
except ModuleNotFoundError:
else:
from airflow.datasets import Dataset as Asset # type: ignore[no-redef]

if TYPE_CHECKING:
Expand Down
10 changes: 8 additions & 2 deletions providers/src/airflow/providers/openlineage/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,9 +720,15 @@ def translate_airflow_asset(asset: Asset, lineage_context) -> OpenLineageDataset
This function returns None if no URI normalizer is defined, no asset converter is found or
some core Airflow changes are missing and ImportError is raised.
"""
try:
# TODO: Remove version check block after bumpping common provider to 1.3.0
from packaging.version import Version

from airflow import __version__ as AIRFLOW_VERSION

AIRFLOW_V_3_0_PLUS = Version(Version(AIRFLOW_VERSION).base_version) >= Version("3.0.0")
if AIRFLOW_V_3_0_PLUS:
from airflow.sdk.definitions.asset import _get_normalized_scheme
except ModuleNotFoundError:
else:
try:
from airflow.datasets import _get_normalized_scheme # type: ignore[no-redef, attr-defined]
except ImportError:
Expand Down

0 comments on commit 158266d

Please sign in to comment.