Skip to content

Commit c357b4c

Browse files
darynaishchenkooctavia-squidington-iii
andauthored
fix(low-code): handle ScannerError in ConfigComponentsResolver (#614)
Co-authored-by: octavia-squidington-iii <[email protected]>
1 parent 0afea4a commit c357b4c

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,20 @@ 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"][
152+
"components_mapping"
153+
].append(
154+
{
155+
"type": "ComponentMappingDefinition",
156+
"create_or_update": True,
157+
"field_path": ["retriever", "requester", "$parameters", "cursor_format"],
158+
"value": "{{ '%Y-%m-%d' if components_values['name'] == 'default_item' else '%Y-%m-%dT%H:%M:%S' }}",
159+
}
160+
)
161+
148162

149163
@pytest.mark.parametrize(
150164
"manifest, config, expected_exception, expected_stream_names",
@@ -157,6 +171,7 @@ def to_configured_catalog(
157171
None,
158172
),
159173
(_MANIFEST_WITH_STREAM_CONFIGS_LIST, _CONFIG, None, ["item_1", "item_2", "default_item"]),
174+
(_MANIFEST_WITH_SCANNER_ERROR, _CONFIG, None, ["item_1", "item_2", "default_item"]),
160175
],
161176
)
162177
def test_dynamic_streams_read_with_config_components_resolver(

0 commit comments

Comments
 (0)