|
104 | 104 | from sqlbuild.executor.python_nodes.types import PythonIdentityRecorder |
105 | 105 | from sqlbuild.executor.run.classes.fingerprint_writes import FingerprintWrites |
106 | 106 | from sqlbuild.executor.run.classes.runtime_watermark_resolver import RuntimeWatermarkResolver |
| 107 | +from sqlbuild.executor.run.constants import RUN_AUDIT_FAILED_CODE |
107 | 108 | from sqlbuild.executor.run.models import ( |
108 | 109 | BatchWindow, |
109 | 110 | BoundViewGuard, |
@@ -258,6 +259,7 @@ def __init__( |
258 | 259 | self._load_results: list[LoadExecutionResult] = list(initial_state.initial_load_results) |
259 | 260 | self._test_results: list[SqlTestExecutionResult] = [] |
260 | 261 | self._source_audit_results: list[AuditExecutionResult] = [] |
| 262 | + self._seed_audit_results: dict[CompiledObjectKey, tuple[AuditExecutionResult, ...]] = {} |
261 | 263 |
|
262 | 264 | self._executed_source_audits: set[str] = set() |
263 | 265 | self._failed_sources: set[str] = set() |
@@ -1004,6 +1006,8 @@ def _execute_seed_node(self, *, key: CompiledObjectKey, connection: Any) -> Seed |
1004 | 1006 | query_change_tracking=self._query_change_tracking, |
1005 | 1007 | schema_prepared=self._schema_prepared, |
1006 | 1008 | ) |
| 1009 | + if result.status == ExecutionStatus.SUCCESS: |
| 1010 | + result = self._with_seed_audits(key=key, result=result, connection=connection) |
1007 | 1011 | duration: int = int((time.monotonic() - start) * 1000) |
1008 | 1012 | completed_result: SeedExecutionResult = dataclasses.replace(result, duration_ms=duration) |
1009 | 1013 | log_debug_event( |
@@ -1346,12 +1350,11 @@ def _handle_completion( |
1346 | 1350 | failed: bool = False |
1347 | 1351 |
|
1348 | 1352 | if isinstance(result, SeedExecutionResult): |
| 1353 | + self._source_audit_results.extend(self._seed_audit_results.pop(key, ())) |
1349 | 1354 | self._seed_results.append(result) |
1350 | 1355 | if self._on_node_complete is not None: |
1351 | 1356 | self._on_node_complete(result) |
1352 | 1357 | failed = result.status == ExecutionStatus.FAILED |
1353 | | - if result.status == ExecutionStatus.SUCCESS and self._run_seed_audits(key=key): |
1354 | | - failed = True |
1355 | 1358 |
|
1356 | 1359 | elif isinstance(result, SqlTestExecutionResult): |
1357 | 1360 | self._test_results.append(result) |
@@ -1404,26 +1407,38 @@ def _handle_completion( |
1404 | 1407 | self._stop = True |
1405 | 1408 | self._mark_complete(key) |
1406 | 1409 |
|
1407 | | - def _run_seed_audits(self, *, key: CompiledObjectKey) -> bool: |
1408 | | - """Run a loaded seed's audits and return whether an error-severity audit failed.""" |
| 1410 | + def _with_seed_audits( |
| 1411 | + self, *, key: CompiledObjectKey, result: SeedExecutionResult, connection: Any |
| 1412 | + ) -> SeedExecutionResult: |
| 1413 | + """Run a loaded seed's audits within its attempt; an error-severity failure fails it.""" |
1409 | 1414 |
|
1410 | 1415 | if not self._run_audits: |
1411 | | - return False |
| 1416 | + return result |
1412 | 1417 | audits: tuple[AuditPlanEntry, ...] = self._indexes.seed_audits_by_seed.get(key.name, ()) |
1413 | 1418 | if not audits: |
1414 | | - return False |
| 1419 | + return result |
1415 | 1420 | results: tuple[AuditExecutionResult, ...] = run_end_audits( |
1416 | 1421 | end_audits=audits, |
1417 | 1422 | adapter=self._adapter, |
1418 | | - connection=self._scheduler_connection, |
| 1423 | + connection=connection, |
1419 | 1424 | model_locations=self._plan.model_locations, |
1420 | 1425 | seed_locations=self._plan.seed_locations, |
1421 | 1426 | source_map=self._plan.source_map, |
1422 | 1427 | run_id=self._run_id, |
1423 | 1428 | quality_scope="seed", |
1424 | 1429 | ) |
1425 | | - self._source_audit_results.extend(results) |
1426 | | - return any(result.outcome == AuditOutcome.ERROR for result in results) |
| 1430 | + self._seed_audit_results[key] = results |
| 1431 | + if not any(audit.outcome == AuditOutcome.ERROR for audit in results): |
| 1432 | + return result |
| 1433 | + return dataclasses.replace( |
| 1434 | + result, |
| 1435 | + status=ExecutionStatus.FAILED, |
| 1436 | + error_code=RUN_AUDIT_FAILED_CODE, |
| 1437 | + error_message=( |
| 1438 | + f"audit for seed '{result.seed_name}' failed after loading " |
| 1439 | + "with severity level: error" |
| 1440 | + ), |
| 1441 | + ) |
1427 | 1442 |
|
1428 | 1443 | def _mark_complete(self, key: CompiledObjectKey) -> None: |
1429 | 1444 | """Mark a key complete and enqueue any downstream that become ready.""" |
|
0 commit comments