Skip to content

Commit

Permalink
Only update crawler tags if present in config dict (#32331)
Browse files Browse the repository at this point in the history
  • Loading branch information
luos-fc authored Jul 6, 2023
1 parent 9a0f41b commit 7a3bc8d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion airflow/providers/amazon/aws/hooks/glue_crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ def update_crawler(self, **crawler_kwargs) -> bool:
crawler_name = crawler_kwargs["Name"]
current_crawler = self.get_crawler(crawler_name)

tags_updated = self.update_tags(crawler_name, crawler_kwargs.pop("Tags", {}))
tags_updated = (
self.update_tags(crawler_name, crawler_kwargs.pop("Tags")) if "Tags" in crawler_kwargs else False
)

update_config = {
key: value
Expand Down
14 changes: 12 additions & 2 deletions tests/providers/amazon/aws/hooks/test_glue_crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,24 @@ def test_remove_all_tags(self, mock_get_conn):
ResourceArn=self.crawler_arn, TagsToRemove=["test", "bar"]
)

@mock_sts
@mock.patch.object(GlueCrawlerHook, "get_conn")
def test_update_missing_tags(self, mock_get_conn):
mock_config_missing_tags = deepcopy(mock_config)
mock_config_missing_tags.pop("Tags")
mock_get_conn.return_value.get_crawler.return_value = {"Crawler": mock_config_missing_tags}

assert self.hook.update_crawler(**mock_config_missing_tags) is False
mock_get_conn.return_value.get_tags.assert_not_called()
mock_get_conn.return_value.tag_resource.assert_not_called()
mock_get_conn.return_value.untag_resource.assert_not_called()

@mock_sts
@mock.patch.object(GlueCrawlerHook, "get_conn")
def test_replace_tag(self, mock_get_conn):
mock_get_conn.return_value.get_crawler.return_value = {"Crawler": mock_config}
mock_get_conn.return_value.get_tags.return_value = {"Tags": mock_config["Tags"]}

mock_config_two = deepcopy(mock_config)
mock_config_two.pop("Tags")
assert self.hook.update_tags(mock_crawler_name, {"test": "bla", "bar": "test"}) is True
mock_get_conn.return_value.get_tags.assert_called_once_with(ResourceArn=self.crawler_arn)
mock_get_conn.return_value.untag_resource.assert_not_called()
Expand Down

0 comments on commit 7a3bc8d

Please sign in to comment.