Skip to content

Commit ec99595

Browse files
authored
Source Amazon Ads: fix bug with handling: "Report date is too far in the past." (#20662)
Signed-off-by: Sergey Chvalyuk <[email protected]>
1 parent f10c765 commit ec99595

File tree

9 files changed

+73
-49
lines changed

9 files changed

+73
-49
lines changed

airbyte-config/init/src/main/resources/seed/source_definitions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
- name: Amazon Ads
5555
sourceDefinitionId: c6b0a29e-1da9-4512-9002-7bfd0cba2246
5656
dockerRepository: airbyte/source-amazon-ads
57-
dockerImageTag: 0.1.25
57+
dockerImageTag: 0.1.26
5858
documentationUrl: https://docs.airbyte.com/integrations/sources/amazon-ads
5959
icon: amazonads.svg
6060
sourceType: api

airbyte-config/init/src/main/resources/seed/source_specs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@
719719
supportsNormalization: false
720720
supportsDBT: false
721721
supported_destination_sync_modes: []
722-
- dockerImage: "airbyte/source-amazon-ads:0.1.25"
722+
- dockerImage: "airbyte/source-amazon-ads:0.1.26"
723723
spec:
724724
documentationUrl: "https://docs.airbyte.com/integrations/sources/amazon-ads"
725725
connectionSpecification:

airbyte-integrations/connectors/source-amazon-ads/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
1313
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
1414

1515

16-
LABEL io.airbyte.version=0.1.25
16+
LABEL io.airbyte.version=0.1.26
1717
LABEL io.airbyte.name=airbyte/source-amazon-ads
Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,55 @@
11
# See [Source Acceptance Tests](https://docs.airbyte.com/connector-development/testing-connectors/source-acceptance-tests-reference)
22
# for more information about how to configure these tests
33
connector_image: airbyte/source-amazon-ads:dev
4-
tests:
4+
acceptance_tests:
55
spec:
6-
- spec_path: "integration_tests/spec.json"
6+
tests:
7+
- spec_path: "integration_tests/spec.json"
78
connection:
8-
- config_path: "secrets/config.json"
9-
status: "succeed"
10-
- config_path: "integration_tests/invalid_config.json"
11-
status: "failed"
9+
tests:
10+
- config_path: "secrets/config.json"
11+
status: "succeed"
12+
- config_path: "integration_tests/invalid_config.json"
13+
status: "failed"
1214
discovery:
13-
- config_path: "secrets/config.json"
15+
tests:
16+
- config_path: "secrets/config.json"
1417
basic_read:
15-
- config_path: "secrets/config.json"
16-
configured_catalog_path: "integration_tests/configured_catalog.json"
17-
expect_records:
18-
path: "integration_tests/expected_records.jsonl"
19-
extra_fields: no
20-
exact_order: no
21-
extra_records: no
22-
empty_streams:
23-
[
24-
"profiles",
25-
"sponsored_brands_ad_groups",
26-
"sponsored_brands_campaigns",
27-
"sponsored_brands_keywords",
28-
"attribution_report_performance_creative",
29-
"attribution_report_performance_adgroup",
30-
"attribution_report_products",
31-
"attribution_report_performance_campaign",
32-
]
33-
- config_path: "secrets/config_report.json"
34-
configured_catalog_path: "integration_tests/configured_catalog_report.json"
35-
timeout_seconds: 2400
18+
tests:
19+
- config_path: "secrets/config.json"
20+
configured_catalog_path: "integration_tests/configured_catalog.json"
21+
expect_records:
22+
path: "integration_tests/expected_records.jsonl"
23+
extra_fields: no
24+
exact_order: no
25+
extra_records: no
26+
empty_streams:
27+
- name: "profiles"
28+
- name: "sponsored_brands_ad_groups"
29+
- name: "sponsored_brands_campaigns"
30+
- name: "sponsored_brands_keywords"
31+
- name: "attribution_report_performance_creative"
32+
- name: "attribution_report_performance_adgroup"
33+
- name: "attribution_report_products"
34+
- name: "attribution_report_performance_campaign"
35+
- config_path: "secrets/config_report.json"
36+
configured_catalog_path: "integration_tests/configured_catalog_report.json"
37+
timeout_seconds: 2400
3638
incremental:
37-
- config_path: "secrets/config_report.json"
38-
configured_catalog_path: "integration_tests/configured_catalog_report.json"
39-
future_state_path: "integration_tests/abnormal_state.json"
40-
cursor_paths:
41-
sponsored_products_report_stream: ["1861552880916640", "reportDate"]
42-
timeout_seconds: 2400
39+
tests:
40+
- config_path: "secrets/config_report.json"
41+
configured_catalog_path: "integration_tests/configured_catalog_report.json"
42+
future_state:
43+
future_state_path: "integration_tests/abnormal_state.json"
44+
cursor_paths:
45+
sponsored_products_report_stream: ["1861552880916640", "reportDate"]
46+
timeout_seconds: 2400
4347
full_refresh:
44-
- config_path: "secrets/config.json"
45-
configured_catalog_path: "integration_tests/configured_catalog.json"
46-
- config_path: "secrets/config_report.json"
47-
configured_catalog_path: "integration_tests/configured_catalog_report.json"
48-
ignored_fields:
49-
"sponsored_products_report_stream": ["updatedAt"]
50-
timeout_seconds: 3600
48+
tests:
49+
- config_path: "secrets/config.json"
50+
configured_catalog_path: "integration_tests/configured_catalog.json"
51+
- config_path: "secrets/config_report.json"
52+
configured_catalog_path: "integration_tests/configured_catalog_report.json"
53+
ignored_fields:
54+
"sponsored_products_report_stream": ["updatedAt"]
55+
timeout_seconds: 3600

airbyte-integrations/connectors/source-amazon-ads/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from setuptools import find_packages, setup
77

8-
MAIN_REQUIREMENTS = ["airbyte-cdk~=0.2", "requests_oauthlib~=1.3.1", "pendulum~=2.1.2"]
8+
MAIN_REQUIREMENTS = ["airbyte-cdk~=0.16", "requests_oauthlib~=1.3.1", "pendulum~=2.1.2"]
99

1010
TEST_REQUIREMENTS = [
1111
"pytest~=6.1",

airbyte-integrations/connectors/source-amazon-ads/source_amazon_ads/source.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,26 @@
3636
SponsoredProductsReportStream,
3737
SponsoredProductTargetings,
3838
)
39+
from .streams.report_streams.report_streams import ReportStream
3940

4041
# Oauth 2.0 authentication URL for amazon
4142
TOKEN_URL = "https://api.amazon.com/auth/o2/token"
4243
CONFIG_DATE_FORMAT = "YYYY-MM-DD"
4344

4445

4546
class SourceAmazonAds(AbstractSource):
46-
def _validate_and_transform(self, config: Mapping[str, Any]):
47+
def _validate_and_transform(self, config: Mapping[str, Any], check=False):
4748
start_date = config.get("start_date")
4849
if start_date:
4950
config["start_date"] = pendulum.from_format(start_date, CONFIG_DATE_FORMAT).date()
51+
if check:
52+
# This validation is used only for improving the user UX experience.
53+
# The connector can work without this low boundary checking.
54+
# We use REPORTING_PERIOD plus ONE additional day because
55+
# amazon account can have multiple profiles in different time zones.
56+
min_date = pendulum.today().date().subtract(days=ReportStream.REPORTING_PERIOD + 1)
57+
if config["start_date"] < min_date:
58+
raise Exception(f"Start Date: minimum allowed value is {min_date}")
5059
else:
5160
config["start_date"] = None
5261
if not config.get("region"):
@@ -61,7 +70,7 @@ def check_connection(self, logger: logging.Logger, config: Mapping[str, Any]) ->
6170
:return Tuple[bool, any]: (True, None) if the input config can be used to connect to the API successfully, (False, error) otherwise.
6271
"""
6372
try:
64-
config = self._validate_and_transform(config)
73+
config = self._validate_and_transform(config, check=True)
6574
except Exception as e:
6675
return False, str(e)
6776
# Check connection by sending list of profiles request. Its most simple

airbyte-integrations/connectors/source-amazon-ads/source_amazon_ads/streams/report_streams/report_streams.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class ReportStream(BasicAmazonAdsStream, ABC):
108108
# Check if the connector received an error: 'Report date is too far in the past. Reports are only available for 60 days.'
109109
# In theory, it does not have to get such an error because the connector correctly calculates the start date,
110110
# but from practice, we can still catch such errors from time to time.
111-
(406, "Report date is too far in the past."),
111+
(406, re.compile(r"^Report date is too far in the past\.")),
112112
]
113113

114114
def __init__(self, config: Mapping[str, Any], profiles: List[Profile], authenticator: Oauth2Authenticator):

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
33
#
44

5+
import pendulum
56
import responses
67
from airbyte_cdk.models import AirbyteConnectionStatus, AirbyteMessage, ConnectorSpecification, Status, Type
8+
from freezegun import freeze_time
79
from jsonschema import Draft4Validator
810
from source_amazon_ads import SourceAmazonAds
911

@@ -41,6 +43,7 @@ def test_spec():
4143

4244

4345
@responses.activate
46+
@freeze_time("2022-12-20 10:00:00")
4447
def test_check(config_gen):
4548
setup_responses()
4649
source = SourceAmazonAds()
@@ -51,7 +54,13 @@ def test_check(config_gen):
5154
assert command_check(source, config_gen(start_date="")) == AirbyteConnectionStatus(status=Status.SUCCEEDED)
5255
assert len(responses.calls) == 4
5356

54-
assert source.check(None, config_gen(start_date="2022-02-20")) == AirbyteConnectionStatus(status=Status.SUCCEEDED)
57+
assert source.check(None, config_gen(start_date="1900-01-01")) == AirbyteConnectionStatus(
58+
status=Status.FAILED, message="'Start Date: minimum allowed value is 2022-10-20'"
59+
)
60+
assert len(responses.calls) == 4
61+
62+
start_date = pendulum.today().format("YYYY-MM-DD")
63+
assert source.check(None, config_gen(start_date=start_date)) == AirbyteConnectionStatus(status=Status.SUCCEEDED)
5564
assert len(responses.calls) == 6
5665

5766
assert command_check(source, config_gen(start_date="2022-20-02")) == AirbyteConnectionStatus(

docs/integrations/sources/amazon-ads.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Information about expected report generation waiting time you may find [here](ht
9494

9595
| Version | Date | Pull Request | Subject |
9696
|:--------|:-----------|:---------------------------------------------------------|:----------------------------------------------------------------------------------------------------------------|
97+
| 0.1.26 | 2022-12-19 | [20662](https://github.com/airbytehq/airbyte/pull/20662) | Fix bug with handling: "Report date is too far in the past." |
9798
| 0.1.25 | 2022-11-08 | [18985](https://github.com/airbytehq/airbyte/pull/18985) | Remove "report_wait_timeout", "report_generation_max_retries" from config |
9899
| 0.1.24 | 2022-10-19 | [17475](https://github.com/airbytehq/airbyte/pull/17475) | Add filters for state on brand, product and display campaigns |
99100
| 0.1.23 | 2022-09-06 | [16342](https://github.com/airbytehq/airbyte/pull/16342) | Add attribution reports |

0 commit comments

Comments
 (0)