Skip to content

Commit

Permalink
Handle github_method_args in GithubOperator when not provided (#29699)
Browse files Browse the repository at this point in the history
The `github_method_args` is an optional parameter for GithubOperator; however, if an arg value is not passed the GithubOperator task fails because `github_method_args` is always expected to be a mapping. It should be possible for users to not need to pass `github_method_args` in GithubOperator when it's not needed.
  • Loading branch information
josh-fell committed Feb 22, 2023
1 parent 8b178f1 commit d4af0ca
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
10 changes: 5 additions & 5 deletions airflow/providers/github/operators/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ class GithubOperator(BaseOperator):
For more information on how to use this operator, take a look at the guide:
:ref:`howto/operator:GithubOperator`
:param github_conn_id: reference to a pre-defined GitHub Connection
:param github_method: method name from GitHub Python SDK to be called
:param github_method_args: required method parameters for the github_method. (templated)
:param result_processor: function to further process the response from GitHub API
:param github_conn_id: Reference to a pre-defined GitHub Connection
:param github_method: Method name from GitHub Python SDK to be called
:param github_method_args: Method parameters for the github_method. (templated)
:param result_processor: Function to further process the response from GitHub API
"""

template_fields = ("github_method_args",)
Expand All @@ -58,7 +58,7 @@ def __init__(
super().__init__(**kwargs)
self.github_conn_id = github_conn_id
self.method_name = github_method
self.github_method_args = github_method_args
self.github_method_args = github_method_args or {}
self.result_processor = result_processor

def execute(self, context: Context) -> Any:
Expand Down
9 changes: 9 additions & 0 deletions tests/providers/github/operators/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ def setup_class(self):
)
)

def test_operator_init_with_optional_args(self):
github_operator = GithubOperator(
task_id="github_list_repos",
github_method="get_user",
)

assert github_operator.github_method_args == {}
assert github_operator.result_processor is None

@patch(
"airflow.providers.github.hooks.github.GithubClient", autospec=True, return_value=github_client_mock
)
Expand Down
1 change: 0 additions & 1 deletion tests/system/providers/github/example_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def tag_checker(repo: Any, tag_name: str) -> bool | None:
github_list_repos = GithubOperator(
task_id="github_list_repos",
github_method="get_user",
github_method_args={},
result_processor=lambda user: logging.info(list(user.get_repos())),
)

Expand Down

0 comments on commit d4af0ca

Please sign in to comment.