Skip to content

Commit b22efc0

Browse files
Source Hubspot: fix "quotes" key error exception (#10055)
* check if stream exists in source * check if stream exists in source, added comment * test skipping reading quotes stream * format code * airbyte-cdk version * added __init__.py to unit_tests * fix importing airbyte models * bump the version * update spec and def yamls Co-authored-by: auganbay <[email protected]>
1 parent 1ed0cc0 commit b22efc0

File tree

7 files changed

+72
-4
lines changed

7 files changed

+72
-4
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@
314314
- name: HubSpot
315315
sourceDefinitionId: 36c891d9-4bd9-43ac-bad2-10e12756272c
316316
dockerRepository: airbyte/source-hubspot
317-
dockerImageTag: 0.1.38
317+
dockerImageTag: 0.1.39
318318
documentationUrl: https://docs.airbyte.io/integrations/sources/hubspot
319319
icon: hubspot.svg
320320
sourceType: api

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3068,7 +3068,7 @@
30683068
supportsNormalization: false
30693069
supportsDBT: false
30703070
supported_destination_sync_modes: []
3071-
- dockerImage: "airbyte/source-hubspot:0.1.38"
3071+
- dockerImage: "airbyte/source-hubspot:0.1.39"
30723072
spec:
30733073
documentationUrl: "https://docs.airbyte.io/integrations/sources/hubspot"
30743074
connectionSpecification:

airbyte-integrations/connectors/source-hubspot/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ COPY source_hubspot ./source_hubspot
3434
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
3535
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
3636

37-
LABEL io.airbyte.version=0.1.38
37+
LABEL io.airbyte.version=0.1.39
3838
LABEL io.airbyte.name=airbyte/source-hubspot

airbyte-integrations/connectors/source-hubspot/source_hubspot/source.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,25 @@
22
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
33
#
44

5+
import logging
6+
from typing import Any, MutableMapping
57

6-
from airbyte_cdk.sources.deprecated.base_source import BaseSource
8+
from airbyte_cdk.sources.deprecated.base_source import BaseClient, BaseSource, ConfiguredAirbyteStream
79

810
from .client import Client
911

1012

1113
class SourceHubspot(BaseSource):
1214
client_class = Client
15+
16+
def _read_stream(
17+
self, logger: logging.Logger, client: BaseClient, configured_stream: ConfiguredAirbyteStream, state: MutableMapping[str, Any]
18+
):
19+
"""
20+
This method is overridden to check if the stream exists in the client.
21+
"""
22+
stream_name = configured_stream.stream.name
23+
if not client._apis.get(stream_name):
24+
logger.warning(f"Stream {stream_name} does not exist in the client.")
25+
return
26+
yield from super()._read_stream(logger=logger, client=client, configured_stream=configured_stream, state=state)

airbyte-integrations/connectors/source-hubspot/unit_tests/__init__.py

Whitespace-only changes.

airbyte-integrations/connectors/source-hubspot/unit_tests/test_client.py

+53
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33
#
44

55

6+
import logging
67
from functools import partial
78

89
import pytest
10+
from airbyte_cdk.sources.deprecated.base_source import ConfiguredAirbyteCatalog, Type
911
from source_hubspot.api import API, PROPERTIES_PARAM_MAX_LENGTH, split_properties
1012
from source_hubspot.client import Client
13+
from source_hubspot.source import SourceHubspot
1114

1215
NUMBER_OF_PROPERTIES = 2000
1316

17+
logger = logging.getLogger("test_client")
18+
1419

1520
@pytest.fixture(name="some_credentials")
1621
def some_credentials_fixture():
@@ -260,3 +265,51 @@ def test_stream_with_splitting_properties_with_new_record(self, requests_mock, c
260265
stream_records = list(test_stream.read(getter=partial(self.get, test_stream.url, api=api)))
261266

262267
assert len(stream_records) == 6
268+
269+
270+
@pytest.fixture(name="oauth_config")
271+
def oauth_config_fixture():
272+
return {
273+
"start_date": "2021-10-10T00:00:00Z",
274+
"credentials": {
275+
"credentials_title": "OAuth Credentials",
276+
"redirect_uri": "https://airbyte.io",
277+
"client_id": "test_client_id",
278+
"client_secret": "test_client_secret",
279+
"refresh_token": "test_refresh_token",
280+
"access_token": "test_access_token",
281+
"token_expires": "2021-05-30T06:00:00Z",
282+
},
283+
}
284+
285+
286+
@pytest.fixture(name="configured_catalog")
287+
def configured_catalog_fixture():
288+
configured_catalog = {
289+
"streams": [
290+
{
291+
"stream": {
292+
"name": "quotes",
293+
"json_schema": {},
294+
"supported_sync_modes": ["full_refresh", "incremental"],
295+
"source_defined_cursor": True,
296+
"default_cursor_field": ["updatedAt"],
297+
},
298+
"sync_mode": "incremental",
299+
"cursor_field": ["updatedAt"],
300+
"destination_sync_mode": "append",
301+
}
302+
]
303+
}
304+
return ConfiguredAirbyteCatalog.parse_obj(configured_catalog)
305+
306+
307+
def test_it_should_not_read_quotes_stream_if_it_does_not_exist_in_client(oauth_config, configured_catalog):
308+
"""
309+
If 'quotes' stream is not in the client, it should skip it.
310+
"""
311+
source = SourceHubspot()
312+
313+
all_records = list(source.read(logger, config=oauth_config, catalog=configured_catalog, state=None))
314+
records = [record for record in all_records if record.type == Type.RECORD]
315+
assert not records

docs/integrations/sources/hubspot.md

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ If you are using Oauth, most of the streams require the appropriate [scopes](htt
112112

113113
| Version | Date | Pull Request | Subject |
114114
|:--------|:-----------| :--- |:-----------------------------------------------------------------------------------------------------------------------------------------------|
115+
| 0.1.39 | 2022-02-10 | [10055](https://github.com/airbytehq/airbyte/pull/10055) | Bug fix: reading not initialized stream |
115116
| 0.1.38 | 2022-02-03 | [9786](https://github.com/airbytehq/airbyte/pull/9786) | Add new streams for engagements(calls, emails, meetings, notes and tasks) |
116117
| 0.1.37 | 2022-01-27 | [9555](https://github.com/airbytehq/airbyte/pull/9555) | Getting form_submission for all forms |
117118
| 0.1.36 | 2022-01-22 | [7784](https://github.com/airbytehq/airbyte/pull/7784) | Add Property History Stream |

0 commit comments

Comments
 (0)