airbyte-cdk 0.31.1__py3-none-any.whl → 0.32.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,10 +6,18 @@ import json
6
6
  import logging
7
7
  from copy import deepcopy
8
8
  from json import JSONDecodeError
9
- from typing import Any, Iterable, Iterator, Mapping, Optional, Union
9
+ from typing import Any, Iterable, Iterator, List, Mapping, Optional, Union
10
10
  from urllib.parse import parse_qs, urlparse
11
11
 
12
- from airbyte_cdk.connector_builder.models import HttpRequest, HttpResponse, LogMessage, StreamRead, StreamReadPages, StreamReadSlices
12
+ from airbyte_cdk.connector_builder.models import (
13
+ HttpRequest,
14
+ HttpResponse,
15
+ LogMessage,
16
+ StreamRead,
17
+ StreamReadPages,
18
+ StreamReadSlices,
19
+ StreamReadSlicesInner,
20
+ )
13
21
  from airbyte_cdk.sources.declarative.declarative_source import DeclarativeSource
14
22
  from airbyte_cdk.utils import AirbyteTracedException
15
23
  from airbyte_cdk.utils.schema_inferrer import SchemaInferrer
@@ -133,7 +141,7 @@ class MessageGrouper:
133
141
  yield StreamReadSlices(pages=current_slice_pages)
134
142
 
135
143
  @staticmethod
136
- def _need_to_close_page(at_least_one_page_in_group, message) -> bool:
144
+ def _need_to_close_page(at_least_one_page_in_group: bool, message: AirbyteMessage) -> bool:
137
145
  return (
138
146
  at_least_one_page_in_group
139
147
  and message.type == MessageType.LOG
@@ -155,7 +163,7 @@ class MessageGrouper:
155
163
  )
156
164
  current_page_records.clear()
157
165
 
158
- def _read_stream(self, source, config, configured_catalog) -> Iterator[AirbyteMessage]:
166
+ def _read_stream(self, source: DeclarativeSource, config: Mapping[str, Any], configured_catalog: ConfiguredAirbyteCatalog) -> Iterator[AirbyteMessage]:
159
167
  # the generator can raise an exception
160
168
  # iterate over the generated messages. if next raise an exception, catch it and yield it as an AirbyteLogMessage
161
169
  try:
@@ -198,7 +206,7 @@ class MessageGrouper:
198
206
  self.logger.warning(f"Failed to parse log message into response object with error: {error}")
199
207
  return None
200
208
 
201
- def _has_reached_limit(self, slices):
209
+ def _has_reached_limit(self, slices: List[StreamReadSlicesInner]):
202
210
  if len(slices) >= self._max_slices:
203
211
  return True
204
212
 
@@ -79,13 +79,9 @@ class AbstractSource(Source, ABC):
79
79
  """Implements the Check Connection operation from the Airbyte Specification.
80
80
  See https://docs.airbyte.com/understanding-airbyte/airbyte-protocol/#check.
81
81
  """
82
- try:
83
- check_succeeded, error = self.check_connection(logger, config)
84
- if not check_succeeded:
85
- return AirbyteConnectionStatus(status=Status.FAILED, message=repr(error))
86
- except Exception as e:
87
- return AirbyteConnectionStatus(status=Status.FAILED, message=repr(e))
88
-
82
+ check_succeeded, error = self.check_connection(logger, config)
83
+ if not check_succeeded:
84
+ return AirbyteConnectionStatus(status=Status.FAILED, message=repr(error))
89
85
  return AirbyteConnectionStatus(status=Status.SUCCEEDED)
90
86
 
91
87
  def read(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: airbyte-cdk
3
- Version: 0.31.1
3
+ Version: 0.32.0
4
4
  Summary: A framework for writing Airbyte Connectors.
5
5
  Home-page: https://github.com/airbytehq/airbyte
6
6
  Author: Airbyte
@@ -8,7 +8,7 @@ airbyte_cdk/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  airbyte_cdk/connector_builder/__init__.py,sha256=4Hw-PX1-VgESLF16cDdvuYCzGJtHntThLF4qIiULWeo,61
9
9
  airbyte_cdk/connector_builder/connector_builder_handler.py,sha256=9iG2hmaJyBtLDtdwtQp8M19pG2HQjR7Yy6jnBDggXMk,4160
10
10
  airbyte_cdk/connector_builder/main.py,sha256=IOijgSQ4A9KhqJplHSVPTrxH_cyGWW_9uNmSIwBo0l0,3021
11
- airbyte_cdk/connector_builder/message_grouper.py,sha256=-0AYh21eZeNJyyFPvSB84NNKMZznSX7bf4Ygi3deWEU,10972
11
+ airbyte_cdk/connector_builder/message_grouper.py,sha256=M58VVaoMYtDVyFnQkqgOyFxVYvxeR2vpnG0kCN3YE1Q,11149
12
12
  airbyte_cdk/connector_builder/models.py,sha256=y0PJ-LwJk3e1RzRmMfjQSBP9ENx_a0wBcWNCjlW72Ks,1832
13
13
  airbyte_cdk/destinations/__init__.py,sha256=0Uxmz3iBAyZJdk_bqUVt2pb0UwRTpFjTnFE6fQFbWKY,126
14
14
  airbyte_cdk/destinations/destination.py,sha256=_tIMnKcRQbtIsjVvNOVjfbIxgCNLuBXQwQj8MyVm3BI,5420
@@ -16,7 +16,7 @@ airbyte_cdk/models/__init__.py,sha256=LPQcYdDPwrCXiBPe_jexO4UAcbovIb1V9tHB6I7Un3
16
16
  airbyte_cdk/models/airbyte_protocol.py,sha256=wKXV_4sCzmUyPndiW7HWAj_A6EDRJyk9cA88xvXGQN0,117
17
17
  airbyte_cdk/models/well_known_types.py,sha256=KKfNbow2gdLoC1Z4hcXy_JR8m_acsB2ol7gQuEgjobw,117
18
18
  airbyte_cdk/sources/__init__.py,sha256=4j6fLtoRCjcZnojpise4EMmQtV1RepBxoGTBgpz80JA,218
19
- airbyte_cdk/sources/abstract_source.py,sha256=Y4jtN7amCon1JJmGH87iZ_Nc1LJHqLas99afyT9JuAk,16034
19
+ airbyte_cdk/sources/abstract_source.py,sha256=KfUAOvsicxAQFrHNXgC0lgDFxB8e6MJBpZPa0ZjqyqU,15895
20
20
  airbyte_cdk/sources/config.py,sha256=PYsY7y2u3EUwxLiEb96JnuKwH_E8CuxKggsRO2ZPSRc,856
21
21
  airbyte_cdk/sources/connector_state_manager.py,sha256=_R-2QnMGimKL0t5aV4f6P1dgd--TB3abY5Seg1xddXk,10469
22
22
  airbyte_cdk/sources/source.py,sha256=N3vHZzdUsBETFsql-YpO-LcgjolT_jcnAuHBhGD6Hqk,4278
@@ -169,7 +169,7 @@ unit_tests/singer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU
169
169
  unit_tests/singer/test_singer_helpers.py,sha256=pZV6VxJuK-3-FICNGmoGbokrA_zkaFZEd4rYZCVpSRU,1762
170
170
  unit_tests/singer/test_singer_source.py,sha256=edN_kv7dnYAdBveWdUYOs74ak0dK6p8uaX225h_ZILA,4442
171
171
  unit_tests/sources/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
172
- unit_tests/sources/test_abstract_source.py,sha256=HJ3I7HvKeWjQ09adlxyec2kmq3WTn9GXuBzHckEBqTQ,39807
172
+ unit_tests/sources/test_abstract_source.py,sha256=ED6OjhaM60YQVV6c6ycRqjwWN0hHfLk_7pyzlaWrqKk,39753
173
173
  unit_tests/sources/test_config.py,sha256=gFXqU_6OjwHXkV4JHMqQUznxmvTWN8nAv0w0-FFpugc,2477
174
174
  unit_tests/sources/test_connector_state_manager.py,sha256=ynFxA63Cxe6t-wMMh9C6ByTlMAuk8W7H2FikDhnUEQ0,24264
175
175
  unit_tests/sources/test_source.py,sha256=xE8LZrvsIp-mbsZmLQMOu3PVC2RmtIQZxjdYbNF4CGg,24151
@@ -257,8 +257,8 @@ unit_tests/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,
257
257
  unit_tests/utils/test_schema_inferrer.py,sha256=ckl17GlNOZInqgxni7Z2A0bg_p6JDy0GVFAG8ph67pw,3288
258
258
  unit_tests/utils/test_secret_utils.py,sha256=XKe0f1RHYii8iwE6ATmBr5JGDI1pzzrnZUGdUSMJQP4,4886
259
259
  unit_tests/utils/test_traced_exception.py,sha256=bDFP5zMBizFenz6V2WvEZTRCKGB5ijh3DBezjbfoYIs,4198
260
- airbyte_cdk-0.31.1.dist-info/LICENSE.txt,sha256=Wfe61S4BaGPj404v8lrAbvhjYR68SHlkzeYrg3_bbuM,1051
261
- airbyte_cdk-0.31.1.dist-info/METADATA,sha256=nSfqOPf-MueD0MHg9bTQU8PWrhP43lmxd6JK1IDNj-M,8902
262
- airbyte_cdk-0.31.1.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
263
- airbyte_cdk-0.31.1.dist-info/top_level.txt,sha256=edvsDKTnE6sD2wfCUaeTfKf5gQIL6CPVMwVL2sWZzqo,51
264
- airbyte_cdk-0.31.1.dist-info/RECORD,,
260
+ airbyte_cdk-0.32.0.dist-info/LICENSE.txt,sha256=Wfe61S4BaGPj404v8lrAbvhjYR68SHlkzeYrg3_bbuM,1051
261
+ airbyte_cdk-0.32.0.dist-info/METADATA,sha256=qSn-QH6VCzY6qd1MjE0AEqjOSZXe8vcqLhZFWqo_XW8,8902
262
+ airbyte_cdk-0.32.0.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
263
+ airbyte_cdk-0.32.0.dist-info/top_level.txt,sha256=edvsDKTnE6sD2wfCUaeTfKf5gQIL6CPVMwVL2sWZzqo,51
264
+ airbyte_cdk-0.32.0.dist-info/RECORD,,
@@ -104,10 +104,11 @@ def test_failed_check():
104
104
  assert expected == MockSource(check_lambda=lambda: (False, "womp womp")).check(logger, {})
105
105
 
106
106
 
107
- def test_raising_check():
107
+ def test_raising_check(mocker):
108
108
  """Tests that if a source raises an unexpected exception the appropriate connectionStatus failure message is returned."""
109
- expected = AirbyteConnectionStatus(status=Status.FAILED, message="Exception('this should fail')")
110
- assert expected == MockSource(check_lambda=lambda: exec('raise Exception("this should fail")')).check(logger, {})
109
+ check_lambda = mocker.Mock(side_effect=BaseException("this should fail"))
110
+ with pytest.raises(BaseException):
111
+ MockSource(check_lambda=check_lambda).check(logger, {})
111
112
 
112
113
 
113
114
  class MockStream(Stream):
@@ -334,10 +335,7 @@ def test_valid_full_refresh_read_with_slices(mocker):
334
335
 
335
336
  @pytest.mark.parametrize(
336
337
  "slices",
337
- [
338
- [{"1": "1"}, {"2": "2"}],
339
- [{"date": datetime.date(year=2023, month=1, day=1)}, {"date": datetime.date(year=2023, month=1, day=1)}]
340
- ]
338
+ [[{"1": "1"}, {"2": "2"}], [{"date": datetime.date(year=2023, month=1, day=1)}, {"date": datetime.date(year=2023, month=1, day=1)}]],
341
339
  )
342
340
  def test_read_full_refresh_with_slices_sends_slice_messages(mocker, slices):
343
341
  """Given the logger is debug and a full refresh, AirbyteMessages are sent for slices"""
@@ -369,7 +367,7 @@ def test_read_incremental_with_slices_sends_slice_messages(mocker):
369
367
  debug_logger.setLevel(logging.DEBUG)
370
368
  slices = [{"1": "1"}, {"2": "2"}]
371
369
  stream = MockStream(
372
- [({"sync_mode": SyncMode.incremental, "stream_slice": s, 'stream_state': {}}, [s]) for s in slices],
370
+ [({"sync_mode": SyncMode.incremental, "stream_slice": s, "stream_state": {}}, [s]) for s in slices],
373
371
  name="s1",
374
372
  )
375
373