Skip to content

Commit e39d396

Browse files
roman-yermilov-gljatinyadav-cc
authored andcommitted
Source Google Ads: temporary patch to avoid 500 Internal server error (airbytehq#35280)
1 parent 4ce6251 commit e39d396

File tree

9 files changed

+48
-26
lines changed

9 files changed

+48
-26
lines changed

airbyte-integrations/connectors/source-google-ads/integration_tests/expected_records.jsonl

Lines changed: 6 additions & 6 deletions
Large diffs are not rendered by default.

airbyte-integrations/connectors/source-google-ads/integration_tests/expected_records_click.jsonl

Lines changed: 9 additions & 8 deletions
Large diffs are not rendered by default.

airbyte-integrations/connectors/source-google-ads/metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ data:
1111
connectorSubtype: api
1212
connectorType: source
1313
definitionId: 253487c0-2246-43ba-a21f-5116b20a2c50
14-
dockerImageTag: 3.3.2
14+
dockerImageTag: 3.3.3
1515
dockerRepository: airbyte/source-google-ads
1616
documentationUrl: https://docs.airbyte.com/integrations/sources/google-ads
1717
githubIssueLabel: source-google-ads

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import logging
77
from enum import Enum
8-
from typing import Any, Iterable, Iterator, List, Mapping, MutableMapping
8+
from typing import Any, Iterable, Iterator, List, Mapping, MutableMapping, Optional
99

1010
import backoff
1111
from airbyte_cdk.models import FailureType
@@ -214,8 +214,18 @@ def get_field_value(field_value: GoogleAdsRow, field: str, schema_type: Mapping[
214214
return field_value
215215

216216
@staticmethod
217-
def parse_single_result(schema: Mapping[str, Any], result: GoogleAdsRow):
217+
def parse_single_result(schema: Mapping[str, Any], result: GoogleAdsRow, nullable: Optional[List[str]] = None):
218+
if nullable is None:
219+
nullable = []
218220
props = schema.get("properties")
219221
fields = GoogleAds.get_fields_from_schema(schema)
220-
single_record = {field: GoogleAds.get_field_value(result, field, props.get(field)) for field in fields}
222+
# Making fields nullable is a temporary try to avoid `500 Internal server error` happen when
223+
# `user_interest.availabilities` and `user_interest.launched_to_all` fields are queried while syncing `user_interest` stream.
224+
# It seems like the values for the fields have changed following the 500 errors and it is unexpected,
225+
# so until we understand the issue with the 500 errors, we will nullify those two fields.
226+
# This should affect only the `user_interest` stream.
227+
# TODO: we need to get rid of the nullable condition once the issue https://github.com/airbytehq/oncall/issues/4306 to be resolved.
228+
single_record = {
229+
field: GoogleAds.get_field_value(result, field, props.get(field)) if field not in nullable else None for field in fields
230+
}
221231
return single_record

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,24 @@ def __init__(self, api: GoogleAds, customers: List[CustomerModel]):
3131
self.customers = customers
3232

3333
def get_query(self, stream_slice: Mapping[str, Any]) -> str:
34-
fields = GoogleAds.get_fields_from_schema(self.get_json_schema())
34+
# The following construction excludes "user_interest.availabilities" and "user_interest.launched_to_all" fields
35+
# from the query because they are a cause of "500 Internal server error" on the google side.
36+
# The oncall issue: https://github.com/airbytehq/oncall/issues/4306
37+
# TODO: replace with fields = GoogleAds.get_fields_from_schema(self.get_json_schema())
38+
fields = [
39+
field
40+
for field in GoogleAds.get_fields_from_schema(self.get_json_schema())
41+
if not (field == "user_interest.availabilities" or field == "user_interest.launched_to_all")
42+
]
3543
table_name = get_resource_name(self.name)
3644
query = GoogleAds.convert_schema_into_query(fields=fields, table_name=table_name)
3745
return query
3846

3947
def parse_response(self, response: SearchPager, stream_slice: Optional[Mapping[str, Any]] = None) -> Iterable[Mapping]:
4048
for result in response:
41-
yield self.google_ads_client.parse_single_result(self.get_json_schema(), result)
49+
yield self.google_ads_client.parse_single_result(
50+
self.get_json_schema(), result, nullable=["user_interest.availabilities", "user_interest.launched_to_all"]
51+
)
4252

4353
def stream_slices(self, stream_state: Mapping[str, Any] = None, **kwargs) -> Iterable[Optional[Mapping[str, any]]]:
4454
for customer in self.customers:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def mock_response_child():
5151

5252

5353
class MockGoogleAds(GoogleAds):
54-
def parse_single_result(self, schema, result):
54+
def parse_single_result(self, schema, result, nullable = None):
5555
return result
5656

5757
def send_request(self, query: str, customer_id: str, login_customer_id: str = "default"):
@@ -219,7 +219,7 @@ def mock_response_4():
219219
class MockGoogleAdsLimit(GoogleAds):
220220
count = 0
221221

222-
def parse_single_result(self, schema, result):
222+
def parse_single_result(self, schema, result, nullable = None):
223223
return result
224224

225225
def send_request(self, query: str, customer_id: str, login_customer_id: str = "default"):

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ def test_get_customers(mocker, customer_status_filter, expected_ids, send_reques
507507

508508
mock_google_api.get_accessible_accounts.return_value = ["123", "789"]
509509
mock_google_api.send_request.side_effect = mock_send_request
510-
mock_google_api.parse_single_result.side_effect = lambda schema, result: result
510+
mock_google_api.parse_single_result.side_effect = lambda schema, result, nullable: result
511511

512512
mock_config = {"customer_status_filter": customer_status_filter, "customer_ids": ["123", "456", "789"]}
513513

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def mock_response_2():
4848
class MockGoogleAds(GoogleAds):
4949
count = 0
5050

51-
def parse_single_result(self, schema, result):
51+
def parse_single_result(self, schema, result, nullable = None):
5252
return result
5353

5454
def send_request(self, query: str, customer_id: str, login_customer_id: str = "none"):

docs/integrations/sources/google-ads.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,9 @@ Due to a limitation in the Google Ads API which does not allow getting performan
280280

281281
| Version | Date | Pull Request | Subject |
282282
|:---------|:-----------|:---------------------------------------------------------|:-------------------------------------------------------------------------------------------------------------------------------------|
283-
| 3.3.2 | 2024-02-12 | [35158](https://github.com/airbytehq/airbyte/pull/35158) | Manage dependencies with Poetry. |
284-
| `3.3.1` | 2024-01-16 | [34007](https://github.com/airbytehq/airbyte/pull/34007) | prepare for airbyte-lib |
283+
| `3.3.3` | 2024-02-14 | [35280](https://github.com/airbytehq/airbyte/pull/35280) | Temporary patch that disables some fields to avoid 500 error when syncing `user_interest` steam |
284+
| `3.3.2` | 2024-02-12 | [35158](https://github.com/airbytehq/airbyte/pull/35158) | Manage dependencies with Poetry. |
285+
| `3.3.1` | 2024-01-16 | [34007](https://github.com/airbytehq/airbyte/pull/34007) | prepare for airbyte-lib |
285286
| `3.3.0` | 2024-01-12 | [34212](https://github.com/airbytehq/airbyte/pull/34212) | Remove metric from query in Ad Group stream for non-manager account |
286287
| `3.2.1` | 2024-01-12 | [34200](https://github.com/airbytehq/airbyte/pull/34200) | Disable raising error for not enabled accounts |
287288
| `3.2.0` | 2024-01-09 | [33707](https://github.com/airbytehq/airbyte/pull/33707) | Add possibility to sync all connected accounts |

0 commit comments

Comments
 (0)