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

Deprecate get_hook in OSSKeySensor and use hook instead #34426

Merged
merged 3 commits into from
Sep 18, 2023
Merged
Changes from 1 commit
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
17 changes: 10 additions & 7 deletions airflow/providers/alibaba/cloud/sensors/oss_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from typing import TYPE_CHECKING, Sequence
from urllib.parse import urlsplit

from deprecated.classic import deprecated

from airflow.exceptions import AirflowException, AirflowSkipException
from airflow.providers.alibaba.cloud.hooks.oss import OSSHook
from airflow.sensors.base import BaseSensorOperator
Expand Down Expand Up @@ -59,7 +61,6 @@ def __init__(
self.bucket_key = bucket_key
self.region = region
self.oss_conn_id = oss_conn_id
self.hook: OSSHook | None = None

def poke(self, context: Context):
"""
Expand Down Expand Up @@ -92,13 +93,15 @@ def poke(self, context: Context):
raise AirflowException(message)

self.log.info("Poking for key : oss://%s/%s", self.bucket_name, self.bucket_key)
return self.get_hook.object_exists(key=self.bucket_key, bucket_name=self.bucket_name)
return self.hook.object_exists(key=self.bucket_key, bucket_name=self.bucket_name)

@cached_property
@property
@deprecated(reason="use `hook` property instead.")
def get_hook(self) -> OSSHook:
"""Create and return an OSSHook."""
if self.hook:
return self.hook

self.hook = OSSHook(oss_conn_id=self.oss_conn_id, region=self.region)
return self.hook

@cached_property
def hook(self) -> OSSHook:
"""Create and return an OSSHook."""
return OSSHook(oss_conn_id=self.oss_conn_id, region=self.region)
Loading