Skip to content

Commit 035264c

Browse files
agarctfioctavia-squidington-iii
andauthored
feat: Add CustomErrorHandler to CompositeErrorHandler list (#786)
Co-authored-by: octavia-squidington-iii <contact@airbyte.com>
1 parent 7a35833 commit 035264c

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

airbyte_cdk/sources/declarative/declarative_component_schema.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ definitions:
391391
anyOf:
392392
- "$ref": "#/definitions/CompositeErrorHandler"
393393
- "$ref": "#/definitions/DefaultErrorHandler"
394+
- "$ref": "#/definitions/CustomErrorHandler"
394395
$parameters:
395396
type: object
396397
additionalProperties: true

airbyte_cdk/sources/declarative/models/declarative_component_schema.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,10 +2149,12 @@ class ConfigAddFields(BaseModel):
21492149

21502150
class CompositeErrorHandler(BaseModel):
21512151
type: Literal["CompositeErrorHandler"]
2152-
error_handlers: List[Union[CompositeErrorHandler, DefaultErrorHandler]] = Field(
2153-
...,
2154-
description="List of error handlers to iterate on to determine how to handle a failed response.",
2155-
title="Error Handlers",
2152+
error_handlers: List[Union[CompositeErrorHandler, DefaultErrorHandler, CustomErrorHandler]] = (
2153+
Field(
2154+
...,
2155+
description="List of error handlers to iterate on to determine how to handle a failed response.",
2156+
title="Error Handlers",
2157+
)
21562158
)
21572159
parameters: Optional[Dict[str, Any]] = Field(None, alias="$parameters")
21582160

unit_tests/sources/declarative/parsers/test_model_to_component_factory.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,6 +2027,44 @@ def test_create_composite_error_handler():
20272027
assert error_handler_1.response_filters[0].action == ResponseAction.RETRY
20282028

20292029

2030+
def test_create_composite_error_handler_with_custom_error_handler():
2031+
content = """
2032+
error_handler:
2033+
type: "CompositeErrorHandler"
2034+
error_handlers:
2035+
- type: "CustomErrorHandler"
2036+
class_name: "unit_tests.sources.declarative.parsers.testing_components.TestingCustomErrorHandler"
2037+
- response_filters:
2038+
- http_codes: [ 429 ]
2039+
action: RETRY
2040+
"""
2041+
parsed_manifest = YamlDeclarativeSource._parse(content)
2042+
resolved_manifest = resolver.preprocess_manifest(parsed_manifest)
2043+
error_handler_manifest = transformer.propagate_types_and_parameters(
2044+
"", resolved_manifest["error_handler"], {}
2045+
)
2046+
2047+
error_handler = factory.create_component(
2048+
model_type=CompositeErrorHandlerModel,
2049+
component_definition=error_handler_manifest,
2050+
config=input_config,
2051+
)
2052+
2053+
assert isinstance(error_handler, CompositeErrorHandler)
2054+
assert len(error_handler.error_handlers) == 2
2055+
2056+
# First error handler should be a custom error handler
2057+
error_handler_0 = error_handler.error_handlers[0]
2058+
assert error_handler_0.__class__.__name__ == "TestingCustomErrorHandler"
2059+
2060+
# Second error handler should be a default error handler
2061+
error_handler_1 = error_handler.error_handlers[1]
2062+
assert isinstance(error_handler_1, DefaultErrorHandler)
2063+
assert isinstance(error_handler_1.response_filters[0], HttpResponseFilter)
2064+
assert error_handler_1.response_filters[0].http_codes == {429}
2065+
assert error_handler_1.response_filters[0].action == ResponseAction.RETRY
2066+
2067+
20302068
# This might be a better test for the manifest transformer but also worth testing end-to-end here as well
20312069
def test_config_with_defaults():
20322070
content = """

unit_tests/sources/declarative/parsers/testing_components.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ def migrate(self, stream_state: Mapping[str, Any]) -> Mapping[str, Any]:
9090
return stream_state
9191

9292

93+
@dataclass
94+
class TestingCustomErrorHandler(DefaultErrorHandler):
95+
"""
96+
A test class based on DefaultErrorHandler used for testing manifests that use custom error handlers.
97+
"""
98+
99+
__test__: ClassVar[bool] = False # Tell Pytest this is not a Pytest class, despite its name
100+
101+
93102
@dataclass
94103
class TestingRequester(HttpRequester):
95104
request_parameters: Optional[RequestInput] = None

0 commit comments

Comments
 (0)