From 08535d9caf8f2b6fafae34c6dea5f0dc3a8f527f Mon Sep 17 00:00:00 2001 From: Baz Date: Sun, 30 Apr 2023 12:18:37 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Source=20Hubspot:=20check=20for?= =?UTF-8?q?=20non-valid=20`start=5Fdate`=20in=20input=20configuration=20(#?= =?UTF-8?q?25667)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../init-oss/src/main/resources/seed/oss_catalog.json | 2 +- .../src/main/resources/seed/source_definitions.yaml | 2 +- .../src/main/resources/seed/source_specs.yaml | 2 +- .../connectors/source-hubspot/Dockerfile | 2 +- .../connectors/source-hubspot/metadata.yaml | 2 +- .../source-hubspot/source_hubspot/errors.py | 11 +++++++++++ .../source-hubspot/source_hubspot/streams.py | 7 +++++-- .../connectors/source-hubspot/unit_tests/conftest.py | 5 +++++ .../source-hubspot/unit_tests/test_source.py | 9 ++++++++- docs/integrations/sources/hubspot.md | 1 + 10 files changed, 35 insertions(+), 8 deletions(-) diff --git a/airbyte-config-oss/init-oss/src/main/resources/seed/oss_catalog.json b/airbyte-config-oss/init-oss/src/main/resources/seed/oss_catalog.json index 40a28186818d7..853994bb21f4c 100644 --- a/airbyte-config-oss/init-oss/src/main/resources/seed/oss_catalog.json +++ b/airbyte-config-oss/init-oss/src/main/resources/seed/oss_catalog.json @@ -15437,7 +15437,7 @@ "sourceDefinitionId": "36c891d9-4bd9-43ac-bad2-10e12756272c", "name": "HubSpot", "dockerRepository": "airbyte/source-hubspot", - "dockerImageTag": "0.6.1", + "dockerImageTag": "0.6.2", "documentationUrl": "https://docs.airbyte.com/integrations/sources/hubspot", "icon": "hubspot.svg", "sourceType": "api", diff --git a/airbyte-config-oss/init-oss/src/main/resources/seed/source_definitions.yaml b/airbyte-config-oss/init-oss/src/main/resources/seed/source_definitions.yaml index c08d2c1e03e86..427099d4b6b93 100644 --- a/airbyte-config-oss/init-oss/src/main/resources/seed/source_definitions.yaml +++ b/airbyte-config-oss/init-oss/src/main/resources/seed/source_definitions.yaml @@ -943,7 +943,7 @@ - name: HubSpot sourceDefinitionId: 36c891d9-4bd9-43ac-bad2-10e12756272c dockerRepository: airbyte/source-hubspot - dockerImageTag: 0.6.1 + dockerImageTag: 0.6.2 documentationUrl: https://docs.airbyte.com/integrations/sources/hubspot icon: hubspot.svg sourceType: api diff --git a/airbyte-config-oss/init-oss/src/main/resources/seed/source_specs.yaml b/airbyte-config-oss/init-oss/src/main/resources/seed/source_specs.yaml index ebe0f2870df88..c8ad8956c7b11 100644 --- a/airbyte-config-oss/init-oss/src/main/resources/seed/source_specs.yaml +++ b/airbyte-config-oss/init-oss/src/main/resources/seed/source_specs.yaml @@ -6968,7 +6968,7 @@ supportsNormalization: false supportsDBT: false supported_destination_sync_modes: [] -- dockerImage: "airbyte/source-hubspot:0.6.1" +- dockerImage: "airbyte/source-hubspot:0.6.2" spec: documentationUrl: "https://docs.airbyte.com/integrations/sources/hubspot" connectionSpecification: diff --git a/airbyte-integrations/connectors/source-hubspot/Dockerfile b/airbyte-integrations/connectors/source-hubspot/Dockerfile index 9cb6ee898f892..e442419faf852 100644 --- a/airbyte-integrations/connectors/source-hubspot/Dockerfile +++ b/airbyte-integrations/connectors/source-hubspot/Dockerfile @@ -34,5 +34,5 @@ COPY source_hubspot ./source_hubspot ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py" ENTRYPOINT ["python", "/airbyte/integration_code/main.py"] -LABEL io.airbyte.version=0.6.1 +LABEL io.airbyte.version=0.6.2 LABEL io.airbyte.name=airbyte/source-hubspot diff --git a/airbyte-integrations/connectors/source-hubspot/metadata.yaml b/airbyte-integrations/connectors/source-hubspot/metadata.yaml index 9fdd230e76b5b..4814fd6498766 100644 --- a/airbyte-integrations/connectors/source-hubspot/metadata.yaml +++ b/airbyte-integrations/connectors/source-hubspot/metadata.yaml @@ -10,7 +10,7 @@ data: connectorSubtype: api connectorType: source definitionId: 36c891d9-4bd9-43ac-bad2-10e12756272c - dockerImageTag: 0.4.0 + dockerImageTag: 0.6.2 dockerRepository: airbyte/source-hubspot githubIssueLabel: source-hubspot icon: hubspot.svg diff --git a/airbyte-integrations/connectors/source-hubspot/source_hubspot/errors.py b/airbyte-integrations/connectors/source-hubspot/source_hubspot/errors.py index a37c76f9160c6..d138e50047918 100644 --- a/airbyte-integrations/connectors/source-hubspot/source_hubspot/errors.py +++ b/airbyte-integrations/connectors/source-hubspot/source_hubspot/errors.py @@ -3,6 +3,8 @@ # +from typing import Any + from requests import HTTPError @@ -31,3 +33,12 @@ class HubspotAccessDenied(HubspotError): class HubspotRateLimited(HubspotError): """429 Rate Limit Reached""" + + +class InvalidStartDateConfigError(Exception): + """Raises when the User inputs wrong or invalid `start_date` in inout configuration""" + + def __init__(self, actual_value: Any, message: str): + super().__init__( + f"The value for `start_date` entered `{actual_value}` is ivalid and could not be processed.\nPlease use the real date/time value.\nFull message: {message}" + ) diff --git a/airbyte-integrations/connectors/source-hubspot/source_hubspot/streams.py b/airbyte-integrations/connectors/source-hubspot/source_hubspot/streams.py index e01423ad3f600..a43411bff7b58 100644 --- a/airbyte-integrations/connectors/source-hubspot/source_hubspot/streams.py +++ b/airbyte-integrations/connectors/source-hubspot/source_hubspot/streams.py @@ -22,7 +22,7 @@ from airbyte_cdk.sources.utils.transform import TransformConfig, TypeTransformer from requests import codes from source_hubspot.constants import OAUTH_CREDENTIALS, PRIVATE_APP_CREDENTIALS -from source_hubspot.errors import HubspotAccessDenied, HubspotInvalidAuth, HubspotRateLimited, HubspotTimeout +from source_hubspot.errors import HubspotAccessDenied, HubspotInvalidAuth, HubspotRateLimited, HubspotTimeout, InvalidStartDateConfigError from source_hubspot.helpers import APIv1Property, APIv3Property, GroupByKey, IRecordPostProcessor, IURLPropertyRepresentation, StoreAsIs # we got this when provided API Token has incorrect format @@ -254,7 +254,10 @@ def __init__(self, api: API, start_date: Union[str, pendulum.datetime], credenti self._start_date = start_date if isinstance(self._start_date, str): - self._start_date = pendulum.parse(self._start_date) + try: + self._start_date = pendulum.parse(self._start_date) + except pendulum.parsing.exceptions.ParserError as e: + raise InvalidStartDateConfigError(self._start_date, e) creds_title = self._credentials["credentials_title"] if creds_title in (OAUTH_CREDENTIALS, PRIVATE_APP_CREDENTIALS): self._authenticator = api.get_authenticator() diff --git a/airbyte-integrations/connectors/source-hubspot/unit_tests/conftest.py b/airbyte-integrations/connectors/source-hubspot/unit_tests/conftest.py index 3e3eacc9bd3a9..a4cde6bb62eb7 100644 --- a/airbyte-integrations/connectors/source-hubspot/unit_tests/conftest.py +++ b/airbyte-integrations/connectors/source-hubspot/unit_tests/conftest.py @@ -37,6 +37,11 @@ def config_fixture(): return {"start_date": "2021-01-10T00:00:00Z", "credentials": {"credentials_title": "Private App Credentials", "access_token": "test_access_token"}} +@pytest.fixture(name="config_invalid_date") +def config_invalid_date_fixture(): + return {"start_date": "2000-00-00T00:00:00Z", "credentials": {"credentials_title": "Private App Credentials", "access_token": "test_access_token"}} + + @pytest.fixture(name="some_credentials") def some_credentials_fixture(): return {"credentials_title": "Private App Credentials", "access_token": "wrong token"} diff --git a/airbyte-integrations/connectors/source-hubspot/unit_tests/test_source.py b/airbyte-integrations/connectors/source-hubspot/unit_tests/test_source.py index eef7a5724c188..cc52d918b6efe 100644 --- a/airbyte-integrations/connectors/source-hubspot/unit_tests/test_source.py +++ b/airbyte-integrations/connectors/source-hubspot/unit_tests/test_source.py @@ -10,7 +10,7 @@ import pendulum import pytest from airbyte_cdk.models import ConfiguredAirbyteCatalog, SyncMode, Type -from source_hubspot.errors import HubspotRateLimited +from source_hubspot.errors import HubspotRateLimited, InvalidStartDateConfigError from source_hubspot.helpers import APIv3Property from source_hubspot.source import SourceHubspot from source_hubspot.streams import API, Companies, Deals, Engagements, MarketingEmails, Products, Stream @@ -61,6 +61,13 @@ def test_check_connection_exception(config): assert error_msg +def test_check_connection_invalid_start_date_exception(config_invalid_date): + with pytest.raises(InvalidStartDateConfigError): + ok, error_msg = SourceHubspot().check_connection(logger, config=config_invalid_date) + assert not ok + assert error_msg + + def test_streams(config): streams = SourceHubspot().streams(config) diff --git a/docs/integrations/sources/hubspot.md b/docs/integrations/sources/hubspot.md index 767e67618b719..1769ab348695a 100644 --- a/docs/integrations/sources/hubspot.md +++ b/docs/integrations/sources/hubspot.md @@ -137,6 +137,7 @@ Now that you have set up the Hubspot source connector, check out the following H | Version | Date | Pull Request | Subject | |:--------|:-----------|:---------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------| +| 0.6.2 | 2023-04-28 | [25667](https://github.com/airbytehq/airbyte/pull/25667) | Fixed bug with `Invalid Date` like `2000-00-00T00:00:00Z` while settip up the connector | | 0.6.1 | 2023-04-10 | [21423](https://github.com/airbytehq/airbyte/pull/21423) | Update scope for `DealPipelines` stream to only `crm.objects.contacts.read` | | 0.6.0 | 2023-04-07 | [24980](https://github.com/airbytehq/airbyte/pull/24980) | Add new stream `DealsArchived` | | 0.5.2 | 2023-04-07 | [24915](https://github.com/airbytehq/airbyte/pull/24915) | Fix field key parsing (replace whitespace with uderscore) |