fix(pfs): is_missing_table_error requires both Catalog and does-not-exist
Matching either substring alone could treat an unrelated error (e.g. a file-not-found message that happens to say "does not exist") as "no derived tables yet, nothing to do" and silently swallow a real bug. Require both, as a real DuckDB Catalog error always carries both.
This commit is contained in:
@@ -226,7 +226,7 @@ def is_missing_table_error(exc: Exception) -> bool:
|
|||||||
``pfs.extract`` so every read-only CPT-table lookup treats a missing
|
``pfs.extract`` so every read-only CPT-table lookup treats a missing
|
||||||
table the same way."""
|
table the same way."""
|
||||||
msg = str(exc)
|
msg = str(exc)
|
||||||
return "Catalog" in msg or "does not exist" in msg
|
return "Catalog" in msg and "does not exist" in msg
|
||||||
|
|
||||||
|
|
||||||
def ensure_tables(con: Any) -> None:
|
def ensure_tables(con: Any) -> None:
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from pfs.codetables import (
|
|||||||
ReviewRow,
|
ReviewRow,
|
||||||
cpt_years,
|
cpt_years,
|
||||||
ensure_tables,
|
ensure_tables,
|
||||||
|
is_missing_table_error,
|
||||||
read_all_elements,
|
read_all_elements,
|
||||||
read_all_events,
|
read_all_events,
|
||||||
read_cpt_codes,
|
read_cpt_codes,
|
||||||
@@ -51,6 +52,27 @@ def _el(code="99490", value="consent", year=2015):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TestIsMissingTableError:
|
||||||
|
def test_true_for_a_real_duckdb_catalog_error(self, con):
|
||||||
|
with pytest.raises(Exception) as exc_info:
|
||||||
|
con.execute("SELECT * FROM pfs.nope")
|
||||||
|
assert is_missing_table_error(exc_info.value)
|
||||||
|
|
||||||
|
def test_false_when_only_catalog_present(self):
|
||||||
|
assert not is_missing_table_error(Exception("Catalog Error: something else"))
|
||||||
|
|
||||||
|
def test_false_when_only_does_not_exist_present(self):
|
||||||
|
# A message that happens to say "does not exist" for an unrelated
|
||||||
|
# reason (not a Catalog error) must not be treated as "missing
|
||||||
|
# table, just nothing derived yet" — that would swallow a real bug.
|
||||||
|
assert not is_missing_table_error(Exception("file does not exist"))
|
||||||
|
|
||||||
|
def test_true_when_both_substrings_present(self):
|
||||||
|
assert is_missing_table_error(
|
||||||
|
Exception('Catalog Error: Table "pfs.code_family" does not exist')
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestDDL:
|
class TestDDL:
|
||||||
def test_idempotent(self, con):
|
def test_idempotent(self, con):
|
||||||
ensure_tables(con)
|
ensure_tables(con)
|
||||||
|
|||||||
Reference in New Issue
Block a user