Skip to content

Commit 201bdb8

Browse files
fix(low-code): handle all ScannerError exceptions in ConfigComponentsResolver (#854)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 15fdf5a commit 201bdb8

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

airbyte_cdk/sources/declarative/resolvers/config_components_resolver.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,10 @@ def _parse_yaml_if_possible(value: Any) -> Any:
204204
return yaml.safe_load(value)
205205
except ParserError: # "{{ record[0] in ['cohortActiveUsers'] }}" # not valid YAML
206206
return value
207-
except ScannerError as e: # "%Y-%m-%d' # not valid yaml
207+
except ScannerError as e: # "%Y-%m-%d" or strings with tabs - not valid YAML
208208
if "expected alphabetic or numeric character, but found '%'" in str(e):
209209
return value
210+
if "found character '\\t' that cannot start any token" in str(e):
211+
return value
210212
raise e
211213
return value

unit_tests/sources/declarative/resolvers/test_config_components_resolver.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,20 @@ def to_configured_catalog(
160160
}
161161
)
162162

163+
# Manifest with component definition with value containing tab characters
164+
# which would cause YAML ScannerError (tabs cannot start tokens in YAML)
165+
_MANIFEST_WITH_TAB_SCANNER_ERROR = deepcopy(_MANIFEST)
166+
_MANIFEST_WITH_TAB_SCANNER_ERROR["dynamic_streams"][0]["components_resolver"][
167+
"components_mapping"
168+
].append(
169+
{
170+
"type": "ComponentMappingDefinition",
171+
"create_or_update": True,
172+
"field_path": ["retriever", "requester", "$parameters", "custom_query"],
173+
"value": "SELECT\n\tcampaign.name,\n\tcampaign.id\nFROM campaign", # Contains tab characters
174+
}
175+
)
176+
163177

164178
@pytest.mark.parametrize(
165179
"manifest, config, expected_exception, expected_stream_names",
@@ -173,8 +187,15 @@ def to_configured_catalog(
173187
),
174188
(_MANIFEST_WITH_STREAM_CONFIGS_LIST, _CONFIG, None, ["item_1", "item_2", "default_item"]),
175189
(_MANIFEST_WITH_SCANNER_ERROR, _CONFIG, None, ["item_1", "item_2", "default_item"]),
190+
(_MANIFEST_WITH_TAB_SCANNER_ERROR, _CONFIG, None, ["item_1", "item_2", "default_item"]),
191+
],
192+
ids=[
193+
"no_duplicates",
194+
"duplicates",
195+
"stream_configs_list",
196+
"scanner_error",
197+
"tab_scanner_error",
176198
],
177-
ids=["no_duplicates", "duplicates", "stream_configs_list", "scanner_error"],
178199
)
179200
def test_dynamic_streams_read_with_config_components_resolver(
180201
manifest, config, expected_exception, expected_stream_names

0 commit comments

Comments
 (0)