Skip to content

Commit

Permalink
Remove GithubOperator use in GithubSensor.__init__()` (#24214)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
josh-fell authored Jun 5, 2022
1 parent daa138c commit 82d5f7c
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions airflow/providers/github/sensors/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 82d5f7c

Please sign in to comment.