This is an automated email from the ASF dual-hosted git repository.
eschutho pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 3e7ae85cc24 fix(importers): catch YAMLError instead of narrower
ParserError in load_yaml (#42426)
3e7ae85cc24 is described below
commit 3e7ae85cc24caa0662c1ab81b34bd56d9dc654e0
Author: Elizabeth Thompson <[email protected]>
AuthorDate: Mon Jul 27 15:03:37 2026 -0700
fix(importers): catch YAMLError instead of narrower ParserError in
load_yaml (#42426)
---
superset/commands/importers/v1/utils.py | 2 +-
.../unit_tests/commands/importers/v1/utils_test.py | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/superset/commands/importers/v1/utils.py
b/superset/commands/importers/v1/utils.py
index 6f07e99dcab..a4124d484a6 100644
--- a/superset/commands/importers/v1/utils.py
+++ b/superset/commands/importers/v1/utils.py
@@ -59,7 +59,7 @@ def load_yaml(file_name: str, content: str) -> dict[str, Any]:
"""Try to load a YAML file"""
try:
return yaml.safe_load(content)
- except yaml.parser.ParserError as ex:
+ except yaml.YAMLError as ex:
logger.exception("Invalid YAML in %s", file_name)
raise ValidationError({file_name: "Not a valid YAML file"}) from ex
diff --git a/tests/unit_tests/commands/importers/v1/utils_test.py
b/tests/unit_tests/commands/importers/v1/utils_test.py
index eef9d4ea2e9..58def5bebef 100644
--- a/tests/unit_tests/commands/importers/v1/utils_test.py
+++ b/tests/unit_tests/commands/importers/v1/utils_test.py
@@ -117,3 +117,24 @@ class TestConvertTemporalColumns:
call_args = mock_logger.warning.call_args[0]
assert call_args[1] == 2 # 2 out-of-bounds, 1 pre-existing null
+
+
+class TestLoadYaml:
+ def test_parser_error_raises_validation_error(self) -> None:
+ """A malformed flow sequence raises yaml.parser.ParserError."""
+ from marshmallow.exceptions import ValidationError
+
+ from superset.commands.importers.v1.utils import load_yaml
+
+ with pytest.raises(ValidationError):
+ load_yaml("test.yaml", "key: [unclosed")
+
+ def test_scanner_error_raises_validation_error(self) -> None:
+ """An unterminated quoted scalar raises yaml.scanner.ScannerError,
+ a sibling of ParserError under yaml.error.YAMLError."""
+ from marshmallow.exceptions import ValidationError
+
+ from superset.commands.importers.v1.utils import load_yaml
+
+ with pytest.raises(ValidationError):
+ load_yaml("test.yaml", 'key: "unterminated string')