Skip to content

Commit

Permalink
Only update crawler tags if present in config dict
Browse files Browse the repository at this point in the history
  • Loading branch information
luos-fc committed Jul 3, 2023
1 parent 985a6cd commit 73e4f11
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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
12 changes: 12 additions & 0 deletions tests/providers/amazon/aws/hooks/test_glue_crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ 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):
Expand Down

0 comments on commit 73e4f11

Please sign in to comment.