You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by jo...@apache.org on 2022/06/05 03:57:13 UTC
[airflow] branch main updated: Remove `GithubOperator` use in `GithubSensor.__init__()`` (#24214)
This is an automated email from the ASF dual-hosted git repository.
joshfell pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 82d5f7cdb7 Remove `GithubOperator` use in `GithubSensor.__init__()`` (#24214)
82d5f7cdb7 is described below
commit 82d5f7cdb7c2879ad561b0edef028b8c5ebb289a
Author: Josh Fell <48...@users.noreply.github.com>
AuthorDate: Sat Jun 4 23:56:59 2022 -0400
Remove `GithubOperator` use in `GithubSensor.__init__()`` (#24214)
The constructor for `GithubSensor` was instantiating `GitHubOperator` to use its `execute()` method as the driver for the result of the sensor's `poke()` logic. However, this could yield a `DuplicateTaskIdFound` when used in DAGs.
This PR updates the `GithubSensor` to use the `GithubHook` instead.
---
airflow/providers/github/sensors/github.py | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/airflow/providers/github/sensors/github.py b/airflow/providers/github/sensors/github.py
index f0501e055b..045cb8f0e1 100644
--- a/airflow/providers/github/sensors/github.py
+++ b/airflow/providers/github/sensors/github.py
@@ -21,7 +21,7 @@ from typing import TYPE_CHECKING, Any, Callable, Optional
from github import GithubException
from airflow import AirflowException
-from airflow.providers.github.operators.github import GithubOperator
+from airflow.providers.github.hooks.github import GithubHook
from airflow.sensors.base import BaseSensorOperator
if TYPE_CHECKING:
@@ -54,16 +54,15 @@ class GithubSensor(BaseSensorOperator):
self.result_processor = result_processor
self.method_name = method_name
self.method_params = method_params
- self.github_operator = GithubOperator(
- task_id=self.task_id,
- github_conn_id=self.github_conn_id,
- github_method=self.method_name,
- github_method_args=self.method_params,
- result_processor=self.result_processor,
- )
def poke(self, context: 'Context') -> bool:
- return self.github_operator.execute(context=context)
+ hook = GithubHook(github_conn_id=self.github_conn_id)
+ github_result = getattr(hook.client, self.method_name)(**self.method_params)
+
+ if self.result_processor:
+ return self.result_processor(github_result)
+
+ return github_result
class BaseGithubRepositorySensor(GithubSensor):