Skip to content

Commit b34f112

Browse files
committed
#12486 #49-alpha-beta-issues PR comment fixes
1 parent 838f515 commit b34f112

File tree

3 files changed

+41
-35
lines changed

3 files changed

+41
-35
lines changed

airbyte-integrations/connectors/source-google-ads/source_google_ads/source.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) ->
9191
for query in config.get("custom_queries", []):
9292
query = query.get("query")
9393
if customer.is_manager_account and self.is_metrics_in_custom_query(query):
94-
return False, f"Metrics are not available for manager account. Check fields in your custom query: {query}"
94+
logger.warning(
95+
f"Metrics are not available for manager account {customer.id}. "
96+
f"Please remove metrics fields in your custom query: {query}."
97+
)
9598
if CustomQuery.cursor_field in query:
9699
return False, f"Custom query should not contain {CustomQuery.cursor_field}"
97100
req_q = CustomQuery.insert_segments_date_expr(query, "1980-01-01", "1980-01-01")
@@ -109,37 +112,38 @@ def streams(self, config: Mapping[str, Any]) -> List[Stream]:
109112
google_api = GoogleAds(credentials=self.get_credentials(config))
110113
accounts = self.get_account_info(google_api, config)
111114
customers = Customer.from_accounts(accounts)
112-
incremental_stream_config = self.get_incremental_stream_config(google_api, config, customers)
115+
non_manager_accounts = [customer for customer in customers if not customer.is_manager_account]
116+
incremental_config = self.get_incremental_stream_config(google_api, config, customers)
117+
non_manager_incremental_config = self.get_incremental_stream_config(google_api, config, non_manager_accounts)
113118
streams = [
114-
AdGroupAds(**incremental_stream_config),
119+
AdGroupAds(**incremental_config),
115120
AdGroupAdLabels(google_api, customers=customers),
116-
AdGroups(**incremental_stream_config),
121+
AdGroups(**incremental_config),
117122
AdGroupLabels(google_api, customers=customers),
118-
Accounts(**incremental_stream_config),
119-
Campaigns(**incremental_stream_config),
123+
Accounts(**incremental_config),
124+
Campaigns(**incremental_config),
120125
CampaignLabels(google_api, customers=customers),
121-
ClickView(**incremental_stream_config),
122-
]
123-
custom_query_streams = [
124-
CustomQuery(custom_query_config=single_query_config, **incremental_stream_config)
125-
for single_query_config in config.get("custom_queries", [])
126+
ClickView(**incremental_config),
126127
]
127-
streams.extend(custom_query_streams)
128-
129128
# Metrics streams cannot be requested for a manager account.
130-
non_manager_accounts = [customer for customer in customers if not customer.is_manager_account]
131129
if non_manager_accounts:
132-
incremental_stream_config["customers"] = non_manager_accounts
133130
streams.extend(
134131
[
135-
UserLocationReport(**incremental_stream_config),
136-
AccountPerformanceReport(**incremental_stream_config),
137-
DisplayTopicsPerformanceReport(**incremental_stream_config),
138-
DisplayKeywordPerformanceReport(**incremental_stream_config),
139-
ShoppingPerformanceReport(**incremental_stream_config),
140-
AdGroupAdReport(**incremental_stream_config),
141-
GeographicReport(**incremental_stream_config),
142-
KeywordReport(**incremental_stream_config),
132+
UserLocationReport(**non_manager_incremental_config),
133+
AccountPerformanceReport(**non_manager_incremental_config),
134+
DisplayTopicsPerformanceReport(**non_manager_incremental_config),
135+
DisplayKeywordPerformanceReport(**non_manager_incremental_config),
136+
ShoppingPerformanceReport(**non_manager_incremental_config),
137+
AdGroupAdReport(**non_manager_incremental_config),
138+
GeographicReport(**non_manager_incremental_config),
139+
KeywordReport(**non_manager_incremental_config),
143140
]
144141
)
142+
for single_query_config in config.get("custom_queries", []):
143+
query = single_query_config.get("query")
144+
if self.is_metrics_in_custom_query(query):
145+
if non_manager_accounts:
146+
streams.append(CustomQuery(custom_query_config=single_query_config, **non_manager_incremental_config))
147+
continue
148+
streams.append(CustomQuery(custom_query_config=single_query_config, **incremental_config))
145149
return streams

airbyte-integrations/connectors/source-google-ads/source_google_ads/streams.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from airbyte_cdk.models import SyncMode
1010
from airbyte_cdk.sources.streams import IncrementalMixin, Stream
1111
from google.ads.googleads.errors import GoogleAdsException
12+
from google.ads.googleads.v9.errors.types.authorization_error import AuthorizationErrorEnum
1213
from google.ads.googleads.v9.errors.types.request_error import RequestErrorEnum
1314
from google.ads.googleads.v9.services.services.google_ads_service.pagers import SearchPager
1415

@@ -115,10 +116,10 @@ def read_records(self, sync_mode, stream_slice: Optional[Mapping[str, Any]] = No
115116
if not self.CATCH_API_ERRORS:
116117
raise
117118
for error in exc.failure.errors:
118-
if error.error_code.authentication_error or error.error_code.authorization_error or error.error_code.query_error:
119+
if error.error_code.authorization_error == AuthorizationErrorEnum.AuthorizationError.CUSTOMER_NOT_ENABLED:
119120
self.logger.error(error.message)
120121
continue
121-
# log and ignore only auth and query errors, otherwise - raise further
122+
# log and ignore only CUSTOMER_NOT_ENABLED error, otherwise - raise further
122123
raise
123124

124125

airbyte-integrations/connectors/source-google-ads/unit_tests/test_source.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from airbyte_cdk import AirbyteLogger
1010
from freezegun import freeze_time
1111
from google.ads.googleads.errors import GoogleAdsException
12+
from google.ads.googleads.v9.errors.types.authorization_error import AuthorizationErrorEnum
1213
from pendulum import today
1314
from source_google_ads.custom_query_stream import CustomQuery
1415
from source_google_ads.google_ads import GoogleAds
@@ -41,15 +42,15 @@ def mock(latest_record):
4142

4243
@pytest.fixture
4344
def mocked_gads_api(mocker):
44-
def mock(response=None, failure_msg="", error_type=""):
45+
def mock(response=None, failure_code=1, failure_msg="", error_type=""):
4546
def side_effect_func():
46-
raise make_google_ads_exception(failure_msg=failure_msg, error_type=error_type)
47+
raise make_google_ads_exception(failure_code=failure_code, failure_msg=failure_msg, error_type=error_type)
4748
yield
4849

4950
side_effect = []
5051
if response:
5152
side_effect.append(response)
52-
if failure_msg or error_type:
53+
if failure_msg or failure_code or error_type:
5354
side_effect.append(side_effect_func())
5455
mocker.patch("source_google_ads.google_ads.GoogleAds.send_request", side_effect=side_effect)
5556

@@ -525,17 +526,17 @@ def test_invalid_custom_query_handled(mocked_gads_api, config):
525526

526527

527528
@pytest.mark.parametrize(
528-
("cls", "error", "raise_expected", "log_expected"),
529+
("cls", "error", "failure_code", "raise_expected", "log_expected"),
529530
(
530-
(AdGroupLabels, "authentication_error", False, True),
531-
(AdGroupLabels, "internal_error", True, False),
532-
(ServiceAccounts, "authentication_error", True, False),
533-
(ServiceAccounts, "internal_error", True, False),
531+
(AdGroupLabels, "authorization_error", AuthorizationErrorEnum.AuthorizationError.CUSTOMER_NOT_ENABLED, False, True),
532+
(AdGroupLabels, "internal_error", 1, True, False),
533+
(ServiceAccounts, "authentication_error", 1, True, False),
534+
(ServiceAccounts, "internal_error", 1, True, False),
534535
),
535536
)
536-
def test_read_record_error_handling(config, customers, caplog, mocked_gads_api, cls, error, raise_expected, log_expected):
537+
def test_read_record_error_handling(config, customers, caplog, mocked_gads_api, cls, error, failure_code, raise_expected, log_expected):
537538
error_msg = "Some unexpected error"
538-
mocked_gads_api(failure_msg=error_msg, error_type=error)
539+
mocked_gads_api(failure_code=failure_code, failure_msg=error_msg, error_type=error)
539540
google_api = GoogleAds(credentials=config["credentials"])
540541
stream = cls(api=google_api, customers=customers)
541542
if raise_expected:

0 commit comments

Comments
 (0)