Skip to content

Commit f9caa5f

Browse files
committed
Bind failed import audits to Dolt state
1 parent e09dc4e commit f9caa5f

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

‎src/openstatspec/sql/wide.py‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,14 @@ def binary64_type() -> Float:
8989
def _record_failed_preflight(
9090
*, engine: Any, normative: Any, operation_id: str, source_name: str,
9191
source_format: str, variable_count: int, profile_name: str,
92-
error: Exception,
92+
active: Mapping[str, Any], error: Exception,
9393
) -> None:
94-
"""Persist a failed preflight in the normative audit catalog."""
95-
with engine.begin() as connection:
94+
"""Persist a failed preflight in the bound normative audit catalog."""
95+
with _bound_catalog_transaction(
96+
engine=engine, profile_name=profile_name, active=active,
97+
audit_relations={normative.operation.name, normative.fidelity_event.name},
98+
phase="import preflight failure",
99+
) as connection:
96100
_verify_normative_catalog(connection, normative)
97101
failed_at = datetime.now(UTC).replace(tzinfo=None)
98102
record_normative_operation(
@@ -832,7 +836,8 @@ def create_wide_dataset(
832836
_record_failed_preflight(
833837
engine=engine, normative=normative, operation_id=operation_id,
834838
source_name=source_name, source_format=source_format,
835-
variable_count=len(variables), profile_name=profile.name, error=error,
839+
variable_count=len(variables), profile_name=profile.name,
840+
active=active_connection, error=error,
836841
)
837842
raise
838843

‎tests/test_catalog_persistence_review.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from openstatspec.core import UnsupportedOperationError
1010
from openstatspec.sql import wide
11+
from openstatspec.sql.profiles import TargetCapabilityExceededError
1112

1213

1314
def _variables():
@@ -91,6 +92,38 @@ def observe(**kwargs):
9192
assert phases == ["catalog initialization", "import"]
9293

9394

95+
def test_failed_import_preflight_routes_audit_through_binding_guard(
96+
tmp_path, monkeypatch,
97+
):
98+
database_url = f"sqlite:///{tmp_path / 'failed-preflight.sqlite'}"
99+
real_bound_transaction = wide._bound_catalog_transaction
100+
phases = []
101+
102+
@contextmanager
103+
def observe(**kwargs):
104+
phases.append(kwargs["phase"])
105+
with real_bound_transaction(**kwargs) as connection:
106+
yield connection
107+
108+
monkeypatch.setattr(wide, "_bound_catalog_transaction", observe)
109+
variables = _variables()
110+
variables[0].update({
111+
"storage_kind": "numeric", "string_width": None,
112+
"format": "F8.2", "alignment": "right",
113+
})
114+
with pytest.raises(TargetCapabilityExceededError):
115+
wide.create_wide_dataset(
116+
database_url=database_url,
117+
dataset_id="invalid",
118+
source_name="invalid.sav",
119+
source_format="SAV",
120+
rows=[{"name": "not-a-number"}],
121+
variables=variables,
122+
)
123+
124+
assert phases == ["catalog initialization", "import preflight failure"]
125+
126+
94127
def test_export_audit_mutations_route_through_binding_guard(tmp_path, monkeypatch):
95128
database_url = f"sqlite:///{tmp_path / 'bound-export.sqlite'}"
96129
_create(database_url)

0 commit comments

Comments
 (0)