@@ -510,6 +510,40 @@ def test_top_level_scalar_is_reported_as_validation_error(
510510 assert len (exceptions ) == 1
511511 assert "databases/malformed.yaml" in exceptions [0 ].messages
512512
513+ def test_unparseable_yaml_is_reported_as_validation_error (
514+ self , session : Session
515+ ) -> None :
516+ """YAML that ``load_yaml`` cannot parse raises a ValidationError
517+ *before* ``config`` is assigned. The ``except ValidationError``
518+ handler's ``isinstance(config, dict)`` diagnostic must not then crash
519+ with an UnboundLocalError (regression for SUPERSET-PYTHON-176W)."""
520+ from superset .commands .importers .v1 .utils import load_configs
521+ from superset .databases .schemas import ImportV1DatabaseSchema
522+ from superset .models .core import Database
523+
524+ engine = session .get_bind ()
525+ Database .metadata .create_all (engine ) # pylint: disable=no-member
526+
527+ # An unterminated quoted scalar raises yaml.scanner.ScannerError,
528+ # mirroring the malformed chart YAML seen in the Sentry report.
529+ contents = {"databases/malformed.yaml" : 'key: "unterminated string' }
530+ exceptions : list [ValidationError ] = []
531+
532+ configs = load_configs (
533+ contents ,
534+ {"databases/" : ImportV1DatabaseSchema ()},
535+ {},
536+ exceptions ,
537+ {},
538+ {},
539+ {},
540+ {},
541+ )
542+
543+ assert configs == {}
544+ assert len (exceptions ) == 1
545+ assert "databases/malformed.yaml" in exceptions [0 ].messages
546+
513547
514548class TestDatabaseConnectionIdentityUnchanged :
515549 """Stored database secrets (password, SSH tunnel key) may only be
0 commit comments