Skip to content

Commit aa66df6

Browse files
handle ScannerError in ConfigComponentsResolver
1 parent 0afea4a commit aa66df6

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

airbyte_cdk/sources/declarative/resolvers/config_components_resolver.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import yaml
1212
from typing_extensions import deprecated
1313
from yaml.parser import ParserError
14+
from yaml.scanner import ScannerError
1415

1516
from airbyte_cdk.sources.declarative.interpolation import InterpolatedString
1617
from airbyte_cdk.sources.declarative.resolvers.components_resolver import (
@@ -185,4 +186,8 @@ def _parse_yaml_if_possible(value: Any) -> Any:
185186
return yaml.safe_load(value)
186187
except ParserError: # "{{ record[0] in ['cohortActiveUsers'] }}" # not valid YAML
187188
return value
189+
except ScannerError as e: # "%Y-%m-%d' # not valid yaml
190+
if "expected alphabetic or numeric character, but found '%'" in str(e):
191+
return value
192+
raise e
188193
return value

unit_tests/sources/declarative/resolvers/test_config_components_resolver.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,17 @@ def to_configured_catalog(
145145
STREAM_CONFIG
146146
]
147147

148+
# Manifest with component definition with value that is fails when trying
149+
# to parse yaml in _parse_yaml_if_possible but generally contains valid string
150+
_MANIFEST_WITH_SCANNER_ERROR = deepcopy(_MANIFEST)
151+
_MANIFEST_WITH_SCANNER_ERROR["dynamic_streams"][0]["components_resolver"]["components_mapping"].append(
152+
{
153+
"type": "ComponentMappingDefinition",
154+
"create_or_update": True,
155+
"field_path": ["retriever", "requester", "$parameters", "cursor_format"],
156+
"value": "{{ '%Y-%m-%d' if components_values['name'] == 'default_item' else '%Y-%m-%dT%H:%M:%S' }}",
157+
}
158+
)
148159

149160
@pytest.mark.parametrize(
150161
"manifest, config, expected_exception, expected_stream_names",
@@ -157,6 +168,7 @@ def to_configured_catalog(
157168
None,
158169
),
159170
(_MANIFEST_WITH_STREAM_CONFIGS_LIST, _CONFIG, None, ["item_1", "item_2", "default_item"]),
171+
(_MANIFEST_WITH_SCANNER_ERROR, _CONFIG, None, ["item_1", "item_2", "default_item"]),
160172
],
161173
)
162174
def test_dynamic_streams_read_with_config_components_resolver(

0 commit comments

Comments
 (0)