From 7772a90ba62d32581fd70bd430b8013bb041a9e9 Mon Sep 17 00:00:00 2001 From: Josh Fell Date: Sat, 4 Jun 2022 23:26:52 -0400 Subject: [PATCH] Remove `GithubOperator` use in `GithubSensor.__init__()`` 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 f0501e055b173..045cb8f0e18b8 100644 --- a/airflow/providers/github/sensors/github.py +++ b/airflow/providers/github/sensors/github.py @@ -21,7 +21,7 @@ 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 @@ def __init__( 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):