From 23ef1c15dfff71c55baed37db939363d3fc83327 Mon Sep 17 00:00:00 2001 From: Serhii Chvaliuk Date: Fri, 6 Jan 2023 17:18:50 +0200 Subject: [PATCH] Source Amazon Ads: fix bug with handling: "Report date is too far in the past." (partial revert of #20662) (#21082) * Revert "Source Amazon Ads: fix bug with handling: "Report date is too far in the past." (#20662)" This reverts commit ec995959f7af3574cd7a6a5e63d2c2aaf3118183. * fix Signed-off-by: Sergey Chvalyuk * revert master Signed-off-by: Sergey Chvalyuk * revert to master Signed-off-by: Sergey Chvalyuk * bump 0.1.27 Signed-off-by: Sergey Chvalyuk * fix Signed-off-by: Sergey Chvalyuk * amazon-ads.md updated Signed-off-by: Sergey Chvalyuk * amazon-ads.md updated Signed-off-by: Sergey Chvalyuk * auto-bump connector version Signed-off-by: Sergey Chvalyuk Co-authored-by: Augustin Co-authored-by: Octavia Squidington III Co-authored-by: Topher Lubaway --- .../src/main/resources/seed/source_definitions.yaml | 2 +- .../init/src/main/resources/seed/source_specs.yaml | 2 +- .../connectors/source-amazon-ads/Dockerfile | 2 +- .../source-amazon-ads/source_amazon_ads/source.py | 13 ++----------- .../source-amazon-ads/unit_tests/test_source.py | 11 +---------- docs/integrations/sources/amazon-ads.md | 1 + 6 files changed, 7 insertions(+), 24 deletions(-) diff --git a/airbyte-config/init/src/main/resources/seed/source_definitions.yaml b/airbyte-config/init/src/main/resources/seed/source_definitions.yaml index 71686613f7680..5f184fb637d08 100644 --- a/airbyte-config/init/src/main/resources/seed/source_definitions.yaml +++ b/airbyte-config/init/src/main/resources/seed/source_definitions.yaml @@ -54,7 +54,7 @@ - name: Amazon Ads sourceDefinitionId: c6b0a29e-1da9-4512-9002-7bfd0cba2246 dockerRepository: airbyte/source-amazon-ads - dockerImageTag: 0.1.26 + dockerImageTag: 0.1.27 documentationUrl: https://docs.airbyte.com/integrations/sources/amazon-ads icon: amazonads.svg sourceType: api diff --git a/airbyte-config/init/src/main/resources/seed/source_specs.yaml b/airbyte-config/init/src/main/resources/seed/source_specs.yaml index 23b66d631a78a..a36d33102f12f 100644 --- a/airbyte-config/init/src/main/resources/seed/source_specs.yaml +++ b/airbyte-config/init/src/main/resources/seed/source_specs.yaml @@ -719,7 +719,7 @@ supportsNormalization: false supportsDBT: false supported_destination_sync_modes: [] -- dockerImage: "airbyte/source-amazon-ads:0.1.26" +- dockerImage: "airbyte/source-amazon-ads:0.1.27" spec: documentationUrl: "https://docs.airbyte.com/integrations/sources/amazon-ads" connectionSpecification: diff --git a/airbyte-integrations/connectors/source-amazon-ads/Dockerfile b/airbyte-integrations/connectors/source-amazon-ads/Dockerfile index ae0a5ce88f265..c886f587e32f2 100644 --- a/airbyte-integrations/connectors/source-amazon-ads/Dockerfile +++ b/airbyte-integrations/connectors/source-amazon-ads/Dockerfile @@ -13,5 +13,5 @@ ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py" ENTRYPOINT ["python", "/airbyte/integration_code/main.py"] -LABEL io.airbyte.version=0.1.26 +LABEL io.airbyte.version=0.1.27 LABEL io.airbyte.name=airbyte/source-amazon-ads diff --git a/airbyte-integrations/connectors/source-amazon-ads/source_amazon_ads/source.py b/airbyte-integrations/connectors/source-amazon-ads/source_amazon_ads/source.py index a2d8179310b63..5810971db1d52 100644 --- a/airbyte-integrations/connectors/source-amazon-ads/source_amazon_ads/source.py +++ b/airbyte-integrations/connectors/source-amazon-ads/source_amazon_ads/source.py @@ -36,7 +36,6 @@ SponsoredProductsReportStream, SponsoredProductTargetings, ) -from .streams.report_streams.report_streams import ReportStream # Oauth 2.0 authentication URL for amazon TOKEN_URL = "https://api.amazon.com/auth/o2/token" @@ -44,18 +43,10 @@ class SourceAmazonAds(AbstractSource): - def _validate_and_transform(self, config: Mapping[str, Any], check=False): + def _validate_and_transform(self, config: Mapping[str, Any]): start_date = config.get("start_date") if start_date: config["start_date"] = pendulum.from_format(start_date, CONFIG_DATE_FORMAT).date() - if check: - # This validation is used only for improving the user UX experience. - # The connector can work without this low boundary checking. - # We use REPORTING_PERIOD plus ONE additional day because - # amazon account can have multiple profiles in different time zones. - min_date = pendulum.today().date().subtract(days=ReportStream.REPORTING_PERIOD + 1) - if config["start_date"] < min_date: - raise Exception(f"Start Date: minimum allowed value is {min_date}") else: config["start_date"] = None if not config.get("region"): @@ -70,7 +61,7 @@ def check_connection(self, logger: logging.Logger, config: Mapping[str, Any]) -> :return Tuple[bool, any]: (True, None) if the input config can be used to connect to the API successfully, (False, error) otherwise. """ try: - config = self._validate_and_transform(config, check=True) + config = self._validate_and_transform(config) except Exception as e: return False, str(e) # Check connection by sending list of profiles request. Its most simple diff --git a/airbyte-integrations/connectors/source-amazon-ads/unit_tests/test_source.py b/airbyte-integrations/connectors/source-amazon-ads/unit_tests/test_source.py index d4b4856b4d299..5a28cf92975e5 100644 --- a/airbyte-integrations/connectors/source-amazon-ads/unit_tests/test_source.py +++ b/airbyte-integrations/connectors/source-amazon-ads/unit_tests/test_source.py @@ -2,10 +2,8 @@ # Copyright (c) 2022 Airbyte, Inc., all rights reserved. # -import pendulum import responses from airbyte_cdk.models import AirbyteConnectionStatus, AirbyteMessage, ConnectorSpecification, Status, Type -from freezegun import freeze_time from jsonschema import Draft4Validator from source_amazon_ads import SourceAmazonAds @@ -43,7 +41,6 @@ def test_spec(): @responses.activate -@freeze_time("2022-12-20 10:00:00") def test_check(config_gen): setup_responses() source = SourceAmazonAds() @@ -54,13 +51,7 @@ def test_check(config_gen): assert command_check(source, config_gen(start_date="")) == AirbyteConnectionStatus(status=Status.SUCCEEDED) assert len(responses.calls) == 4 - assert source.check(None, config_gen(start_date="1900-01-01")) == AirbyteConnectionStatus( - status=Status.FAILED, message="'Start Date: minimum allowed value is 2022-10-20'" - ) - assert len(responses.calls) == 4 - - start_date = pendulum.today().format("YYYY-MM-DD") - assert source.check(None, config_gen(start_date=start_date)) == AirbyteConnectionStatus(status=Status.SUCCEEDED) + assert source.check(None, config_gen(start_date="2022-02-20")) == AirbyteConnectionStatus(status=Status.SUCCEEDED) assert len(responses.calls) == 6 assert command_check(source, config_gen(start_date="2022-20-02")) == AirbyteConnectionStatus( diff --git a/docs/integrations/sources/amazon-ads.md b/docs/integrations/sources/amazon-ads.md index ad2bbdc503760..cf501d1b2bfce 100644 --- a/docs/integrations/sources/amazon-ads.md +++ b/docs/integrations/sources/amazon-ads.md @@ -94,6 +94,7 @@ Information about expected report generation waiting time you may find [here](ht | Version | Date | Pull Request | Subject | |:--------|:-----------|:---------------------------------------------------------|:----------------------------------------------------------------------------------------------------------------| +| 0.1.27 | 2023-01-05 | [21082](https://github.com/airbytehq/airbyte/pull/21082) | Fix bug with handling: "Report date is too far in the past." - partial revert of #20662 | | 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." | | 0.1.25 | 2022-11-08 | [18985](https://github.com/airbytehq/airbyte/pull/18985) | Remove "report_wait_timeout", "report_generation_max_retries" from config | | 0.1.24 | 2022-10-19 | [17475](https://github.com/airbytehq/airbyte/pull/17475) | Add filters for state on brand, product and display campaigns |