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 276b7e2d678 fix(importers): catch YAMLError instead of narrower
ParserError in dataset v0 importer (#42442)
276b7e2d678 is described below
commit 276b7e2d678a7ea8e9a5504ca10456082fdb75ef
Author: Elizabeth Thompson <[email protected]>
AuthorDate: Mon Jul 27 15:04:52 2026 -0700
fix(importers): catch YAMLError instead of narrower ParserError in dataset
v0 importer (#42442)
---
superset/commands/dataset/importers/v0.py | 2 +-
.../datasets/commands/importers/v0/import_test.py | 30 ++++++++++++++++++++++
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/superset/commands/dataset/importers/v0.py
b/superset/commands/dataset/importers/v0.py
index 37e8a82caf8..a3314d984cc 100644
--- a/superset/commands/dataset/importers/v0.py
+++ b/superset/commands/dataset/importers/v0.py
@@ -298,7 +298,7 @@ class ImportDatasetsCommand(BaseCommand):
for file_name, content in self.contents.items():
try:
config = yaml.safe_load(content)
- except yaml.parser.ParserError as ex:
+ except yaml.YAMLError as ex:
logger.exception("Invalid YAML file")
raise IncorrectVersionError(
f"{file_name} is not a valid YAML file"
diff --git a/tests/unit_tests/datasets/commands/importers/v0/import_test.py
b/tests/unit_tests/datasets/commands/importers/v0/import_test.py
index 969c6d1ee1c..71a40479b47 100644
--- a/tests/unit_tests/datasets/commands/importers/v0/import_test.py
+++ b/tests/unit_tests/datasets/commands/importers/v0/import_test.py
@@ -75,3 +75,33 @@ def test_import_from_dict_skips_check_without_user(mocker:
MockerFixture) -> Non
can_access.assert_not_called()
imported.assert_called_once()
+
+
+def test_validate_parser_error_raises_incorrect_version_error() -> None:
+ """
+ A YAML file malformed in a way that raises ``yaml.parser.ParserError``
+ (an unterminated flow sequence) is reported as an invalid version.
+ """
+ from superset.commands.dataset.importers import v0
+ from superset.commands.importers.exceptions import IncorrectVersionError
+
+ command = v0.ImportDatasetsCommand({"broken.yaml": "[1, 2"})
+
+ with pytest.raises(IncorrectVersionError):
+ command.validate()
+
+
+def test_validate_scanner_error_raises_incorrect_version_error() -> None:
+ """
+ A YAML file malformed in a way that raises ``yaml.scanner.ScannerError``
+ (an unterminated quoted string) is a sibling of ``ParserError`` under
+ ``yaml.YAMLError`` and must also be reported as an invalid version rather
+ than propagating as a raw, uncaught exception.
+ """
+ from superset.commands.dataset.importers import v0
+ from superset.commands.importers.exceptions import IncorrectVersionError
+
+ command = v0.ImportDatasetsCommand({"broken.yaml": 'key: "unterminated
string'})
+
+ with pytest.raises(IncorrectVersionError):
+ command.validate()