From 1cadf39ce82ecce5dc12d63cfb904b6452daaffc Mon Sep 17 00:00:00 2001 From: Elizabeth Thompson Date: Fri, 28 Aug 2026 22:14:52 +0000 Subject: [PATCH] test(sql): cover SqlglotError fallback branch in parse_predicate The regression test only exercised the ParseError branch, leaving the generic sqlglot.errors.SqlglotError fallback in SQLStatement.parse_predicate uncovered and dropping line coverage below the 100% gate. Add a test that mocks sqlglot.parse_one to raise a bare SqlglotError and asserts it is converted to a SupersetParseError. --- tests/unit_tests/sql/parse_tests.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/unit_tests/sql/parse_tests.py b/tests/unit_tests/sql/parse_tests.py index 4534c240f84..85781372d78 100644 --- a/tests/unit_tests/sql/parse_tests.py +++ b/tests/unit_tests/sql/parse_tests.py @@ -5592,6 +5592,27 @@ def test_parse_predicate_invalid_sql_raises_superset_parse_error() -> None: assert excinfo.value.status == 422 +def test_parse_predicate_sqlglot_error_raises_superset_parse_error( + mocker: MockerFixture, +) -> None: + """ + A non-``ParseError`` ``sqlglot`` failure also surfaces as a typed error. + + ``parse_predicate`` catches the generic ``SqlglotError`` base class as a + fallback so any sqlglot failure (e.g. tokenize errors) is converted into a + ``SupersetParseError`` rather than leaking a raw sqlglot exception. + """ + # Build the statement before patching, since the constructor also parses. + stmt = SQLStatement("SELECT 1", "postgresql") + mocker.patch( + "sqlglot.parse_one", + side_effect=sqlglot.errors.SqlglotError("boom"), + ) + with pytest.raises(SupersetParseError) as excinfo: + stmt.parse_predicate("a > 1") + assert excinfo.value.status == 422 + + @pytest.mark.usefixtures("_small_parse_cap") def test_transpile_to_dialect_length_check() -> None: """