Skip to content

Commit d99a964

Browse files
fix(low-code): handle all ScannerError exceptions in ConfigComponentsResolver
Previously, the _parse_yaml_if_possible method only caught ScannerError exceptions containing '%' characters, but re-raised other ScannerError types. This caused failures when strings containing tab characters were passed through the YAML parser, as tabs cannot start tokens in YAML. This fix catches all ScannerError exceptions and returns the original value unchanged, which is the expected behavior for strings that are not valid YAML. Fixes: airbytehq/oncall#10280 Co-Authored-By: unknown <>
1 parent 80b7668 commit d99a964

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

airbyte_cdk/sources/declarative/resolvers/config_components_resolver.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,6 @@ 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
208-
if "expected alphabetic or numeric character, but found '%'" in str(e):
209-
return value
210-
raise e
207+
except ScannerError: # "%Y-%m-%d" or strings with tabs - not valid YAML
208+
return value
211209
return value

unit_tests/sources/declarative/resolvers/test_config_components_resolver.py

Lines changed: 16 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,9 @@ 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"]),
176191
],
177-
ids=["no_duplicates", "duplicates", "stream_configs_list", "scanner_error"],
192+
ids=["no_duplicates", "duplicates", "stream_configs_list", "scanner_error", "tab_scanner_error"],
178193
)
179194
def test_dynamic_streams_read_with_config_components_resolver(
180195
manifest, config, expected_exception, expected_stream_names

0 commit comments

Comments
 (0)