Skip to content

Commit 15eadf7

Browse files
Move all BaseHook usages to version_compat in openai (#52819)
Co-authored-by: Amogh Desai <amoghrajesh1999@gmail.com>
1 parent d3a2617 commit 15eadf7

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

providers/openai/src/airflow/providers/openai/hooks/openai.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@
4444
)
4545
from openai.types.vector_stores import VectorStoreFile, VectorStoreFileBatch, VectorStoreFileDeleted
4646
from airflow.providers.openai.exceptions import OpenAIBatchJobException, OpenAIBatchTimeout
47-
48-
try:
49-
from airflow.sdk import BaseHook
50-
except ImportError:
51-
from airflow.hooks.base import BaseHook # type: ignore[attr-defined,no-redef]
47+
from airflow.providers.openai.version_compat import BaseHook
5248

5349

5450
class BatchStatus(str, Enum):

providers/openai/src/airflow/providers/openai/version_compat.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,22 @@ def get_base_airflow_version_tuple() -> tuple[int, int, int]:
3333

3434

3535
AIRFLOW_V_3_0_PLUS = get_base_airflow_version_tuple() >= (3, 0, 0)
36+
AIRFLOW_V_3_1_PLUS: bool = get_base_airflow_version_tuple() >= (3, 1, 0)
37+
38+
39+
if AIRFLOW_V_3_1_PLUS:
40+
from airflow.sdk import BaseHook
41+
else:
42+
from airflow.hooks.base import BaseHook # type: ignore[attr-defined,no-redef]
3643

3744
if AIRFLOW_V_3_0_PLUS:
3845
from airflow.sdk import BaseOperator
3946
else:
4047
from airflow.models import BaseOperator # type: ignore[no-redef]
4148

42-
__all__ = ["AIRFLOW_V_3_0_PLUS", "BaseOperator"]
49+
__all__ = [
50+
"AIRFLOW_V_3_0_PLUS",
51+
"AIRFLOW_V_3_1_PLUS",
52+
"BaseHook",
53+
"BaseOperator",
54+
]

0 commit comments

Comments
 (0)