Skip to content

🎉 Source Google Ads: Add Unrecognized Field description while check_connection #36208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ data:
connectorSubtype: api
connectorType: source
definitionId: 253487c0-2246-43ba-a21f-5116b20a2c50
dockerImageTag: 3.3.6
dockerImageTag: 3.3.7
dockerRepository: airbyte/source-google-ads
documentationUrl: https://docs.airbyte.com/integrations/sources/google-ads
githubIssueLabel: source-google-ads
Expand Down
161 changes: 81 additions & 80 deletions airbyte-integrations/connectors/source-google-ads/poetry.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = [ "poetry-core>=1.0.0",]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
version = "3.3.6"
version = "3.3.7"
name = "source-google-ads"
description = "Source implementation for Google Ads."
authors = [ "Airbyte <[email protected]>",]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#


import logging
from typing import Any, List, Mapping

from airbyte_cdk.config_observation import create_connector_config_control_message
Expand All @@ -15,8 +14,6 @@

from .utils import GAQL

logger = logging.getLogger("airbyte_logger")

FULL_REFRESH_CUSTOM_TABLE = [
"asset",
"asset_group_listing_group_filter",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#


import logging
from enum import Enum
from typing import Any, Iterable, Iterator, List, Mapping, MutableMapping

Expand All @@ -16,8 +15,9 @@
from google.auth import exceptions
from proto.marshal.collections import Repeated, RepeatedComposite

from .utils import logger

API_VERSION = "v15"
logger = logging.getLogger("airbyte")


class GoogleAds:
Expand Down Expand Up @@ -74,7 +74,12 @@ def get_accessible_accounts(self):
),
max_tries=5,
)
def send_request(self, query: str, customer_id: str, login_customer_id: str = "default") -> Iterator[SearchGoogleAdsResponse]:
def send_request(
self,
query: str,
customer_id: str,
login_customer_id: str = "default",
) -> Iterator[SearchGoogleAdsResponse]:
client = self.get_client(login_customer_id)
search_request = client.get_type("SearchGoogleAdsRequest")
search_request.query = query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
UserInterest,
UserLocationView,
)
from .utils import GAQL

logger = logging.getLogger("airbyte")
from .utils import GAQL, logger, traced_exception


class SourceGoogleAds(AbstractSource):
Expand Down Expand Up @@ -191,6 +189,7 @@ def check_connection(self, logger: logging.Logger, config: Mapping[str, Any]) ->
# Check custom query request validity by sending metric request with non-existent time window
for customer in customers:
for query in config.get("custom_queries_array", []):
table_name = query["table_name"]
query = query["query"]
if customer.is_manager_account and self.is_metrics_in_custom_query(query):
logger.warning(
Expand All @@ -205,7 +204,14 @@ def check_connection(self, logger: logging.Logger, config: Mapping[str, Any]) ->
query = IncrementalCustomQuery.insert_segments_date_expr(query, "1980-01-01", "1980-01-01")

query = query.set_limit(1)
response = google_api.send_request(str(query), customer_id=customer.id, login_customer_id=customer.login_customer_id)
try:
response = google_api.send_request(
str(query),
customer_id=customer.id,
login_customer_id=customer.login_customer_id,
)
except Exception as exc:
traced_exception(exc, customer.id, False, table_name)
# iterate over the response otherwise exceptions will not be raised!
for _ in response:
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

import functools
import logging
import queue
import re
import threading
Expand All @@ -17,10 +18,12 @@
from google.ads.googleads.errors import GoogleAdsException
from google.ads.googleads.v15.errors.types.authentication_error import AuthenticationErrorEnum
from google.ads.googleads.v15.errors.types.authorization_error import AuthorizationErrorEnum
from google.ads.googleads.v15.errors.types.query_error import QueryErrorEnum
from google.ads.googleads.v15.errors.types.quota_error import QuotaErrorEnum
from google.ads.googleads.v15.errors.types.request_error import RequestErrorEnum
from google.api_core.exceptions import Unauthenticated
from source_google_ads.google_ads import logger

logger = logging.getLogger("airbyte")


def get_resource_name(stream_name: str) -> str:
Expand Down Expand Up @@ -54,7 +57,12 @@ def is_error_type(error_value, target_enum_value):
return int(error_value) == int(target_enum_value)


def traced_exception(ga_exception: Union[GoogleAdsException, Unauthenticated], customer_id: str, catch_disabled_customer_error: bool):
def traced_exception(
ga_exception: Union[GoogleAdsException, Unauthenticated],
customer_id: str,
catch_disabled_customer_error: bool,
query_name: Optional[str] = None,
) -> None:
"""Add user-friendly message for GoogleAdsException"""
messages = []
raise_exception = AirbyteTracedException
Expand Down Expand Up @@ -100,6 +108,13 @@ def traced_exception(ga_exception: Union[GoogleAdsException, Unauthenticated], c
"https://support.google.com/google-ads/answer/2375392."
)

elif is_error_type(query_error, QueryErrorEnum.QueryError.UNRECOGNIZED_FIELD):
message = (
f"The Custom Query: `{query_name}` has {error.message.lower()} Please make sure the field exists or name entered is valid."
)
# additionally log the error for visability during `check_connection` in UI.
logger.error(message)

elif query_error:
message = f"Incorrect custom query. {error.message}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ def __init__(self, name):
"failure_msg": "Error in query: unexpected end of query.",
"error_type": "queryError",
},
"UNRECOGNIZED_FIELD": {
"failure_code": QueryErrorEnum.QueryError.UNRECOGNIZED_FIELD,
"failure_msg": "unrecognized field in the query.",
"error_type": "queryError",
},
"RESOURCE_EXHAUSTED": {"failure_code": QuotaErrorEnum.QuotaError.RESOURCE_EXHAUSTED, "failure_msg": "msg4", "error_type": "quotaError"},
"UNEXPECTED_ERROR": {
"failure_code": AuthorizationErrorEnum.AuthorizationError.UNKNOWN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def mock_get_customers(mocker):
"Failed to access the customer '123'. Ensure the customer is linked to your manager account or check your permissions to access this customer account.",
),
(["QUERY_ERROR"], "Incorrect custom query. Error in query: unexpected end of query."),
(["UNRECOGNIZED_FIELD"], "The Custom Query: `None` has unrecognized field in the query. Please make sure the field exists or name entered is valid."),
(
["RESOURCE_EXHAUSTED"],
(
Expand Down
1 change: 1 addition & 0 deletions docs/integrations/sources/google-ads.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ Due to a limitation in the Google Ads API which does not allow getting performan

| Version | Date | Pull Request | Subject |
|:---------|:-----------|:---------------------------------------------------------|:-------------------------------------------------------------------------------------------------------------------------------------|
| `3.3.7` | 2024-03-15 | [36208](https://github.com/airbytehq/airbyte/pull/36208) | Added error message when there is the `unrecognized field` inside of the `custom query` |
| `3.3.6` | 2024-03-01 | [35664](https://github.com/airbytehq/airbyte/pull/35664) | Fix error for new customers for incremental events streams |
| `3.3.5` | 2024-02-28 | [35709](https://github.com/airbytehq/airbyte/pull/35709) | Handle 2-Step Verification exception as config error |
| `3.3.4` | 2024-02-21 | [35493](https://github.com/airbytehq/airbyte/pull/35493) | Rolling back the patch 3.3.3 made for `user_interest` steam |
Expand Down
Loading