Skip to content

Commit

Permalink
🐛 Source Hubspot: check for non-valid start_date in input configura…
Browse files Browse the repository at this point in the history
…tion (airbytehq#25667)
  • Loading branch information
bazarnov authored and marcosmarxm committed Jun 8, 2023
1 parent 0b0e94b commit 08535d9
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 8 deletions.
Expand Up @@ -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",
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-hubspot/Dockerfile
Expand Up @@ -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
Expand Up @@ -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
Expand Down
Expand Up @@ -3,6 +3,8 @@
#


from typing import Any

from requests import HTTPError


Expand Down Expand Up @@ -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}"
)
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Expand Up @@ -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"}
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions docs/integrations/sources/hubspot.md
Expand Up @@ -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) |
Expand Down

0 comments on commit 08535d9

Please sign in to comment.