@@ -579,18 +579,18 @@ def _bound_catalog_transaction(
579579 try :
580580 with connection .begin ():
581581 yield connection
582+ after = _capture_dolt_state (
583+ connection , profile_name = profile_name ,
584+ audit_relations = audit_relations ,
585+ )
586+ _require_dolt_success_identity (before , after , phase = phase )
582587 except Exception :
583588 after = _capture_dolt_state (
584589 connection , profile_name = profile_name ,
585590 audit_relations = audit_relations ,
586591 )
587592 _dolt_failure_boundary_evidence (before , after )
588593 raise
589- after = _capture_dolt_state (
590- connection , profile_name = profile_name ,
591- audit_relations = audit_relations ,
592- )
593- _require_dolt_success_identity (before , after , phase = phase )
594594
595595
596596def dolt_state_snapshot (
@@ -1417,6 +1417,13 @@ def record_export_operation(
14171417 "source_item" : destination ,
14181418 "details" : operation_details ,
14191419 },) if operation_details else ()),
1420+ {
1421+ "code" : "export-operation-dataset-binding" ,
1422+ "detail" : "Export operation dataset identity recorded for audit." ,
1423+ "severity" : "info" ,
1424+ "source_item" : destination ,
1425+ "details" : {},
1426+ },
14201427 ),
14211428 )
14221429 return operation_id
@@ -1435,6 +1442,30 @@ def _export_operation_row(
14351442 return row
14361443
14371444
1445+ def _export_operation_dataset_id (
1446+ connection : Any , normative : Any , operation_id : str ,
1447+ ) -> str :
1448+ dataset_ids = set (connection .execute (
1449+ select (normative .fidelity_event .c .dataset_id )
1450+ .where (normative .fidelity_event .c .operation_id == operation_id )
1451+ .where (normative .fidelity_event .c .dataset_id .is_not (None ))
1452+ ).scalars ())
1453+ if len (dataset_ids ) != 1 :
1454+ raise UnsupportedOperationError (
1455+ "The export operation is not bound to exactly one dataset."
1456+ )
1457+ dataset_id = str (dataset_ids .pop ())
1458+ if connection .execute (
1459+ select (normative .dataset .c .dataset_id ).where (
1460+ normative .dataset .c .dataset_id == dataset_id
1461+ )
1462+ ).scalar_one_or_none () is None :
1463+ raise UnsupportedOperationError (
1464+ "The export operation dataset no longer exists."
1465+ )
1466+ return dataset_id
1467+
1468+
14381469def finish_export_operation (
14391470 * , database_url : str , operation_id : str ,
14401471 dolt_conformance_source : Any | None = None ,
@@ -1504,12 +1535,15 @@ def fail_export_operation(
15041535 raise UnsupportedOperationError (
15051536 "Only a started export operation can be failed."
15061537 )
1538+ dataset_id = _export_operation_dataset_id (
1539+ connection , normative , operation_id ,
1540+ )
15071541 finish_normative_operation (
15081542 connection , normative , operation_id = operation_id , status = "failed" ,
15091543 )
15101544 record_normative_fidelity_events (
15111545 connection , normative , operation_id = operation_id ,
1512- dataset_id = None , direction = "export" , events = (event ,),
1546+ dataset_id = dataset_id , direction = "export" , events = (event ,),
15131547 )
15141548
15151549
@@ -1529,9 +1563,12 @@ def record_export_backup_retained(
15291563 raise UnsupportedOperationError (
15301564 "A retained backup warning requires a succeeded export."
15311565 )
1566+ dataset_id = _export_operation_dataset_id (
1567+ connection , normative , operation_id ,
1568+ )
15321569 record_normative_fidelity_events (
15331570 connection , normative , operation_id = operation_id ,
1534- dataset_id = None , direction = "export" , events = ({
1571+ dataset_id = dataset_id , direction = "export" , events = ({
15351572 "code" : "backup_retained" ,
15361573 "detail" : "A successful export retained its durable prior-file backup." ,
15371574 "severity" : "warning" ,
@@ -1578,6 +1615,7 @@ def record_export_cleanup_failure(
15781615 normative .operation .c .operation_id == operation_id
15791616 )
15801617 ).mappings ().one_or_none ()
1618+ dataset_id = None
15811619 if row is None :
15821620 failed_at = datetime .now (UTC ).replace (tzinfo = None )
15831621 record_normative_operation (
@@ -1590,12 +1628,15 @@ def record_export_cleanup_failure(
15901628 raise UnsupportedOperationError (
15911629 "Existing export operation cannot transition to cleanup failure."
15921630 )
1631+ dataset_id = _export_operation_dataset_id (
1632+ connection , normative , operation_id ,
1633+ )
15931634 finish_normative_operation (
15941635 connection , normative , operation_id = operation_id , status = "failed" ,
15951636 )
15961637 record_normative_fidelity_events (
15971638 connection , normative , operation_id = operation_id ,
1598- dataset_id = None , direction = "export" , events = (event ,),
1639+ dataset_id = dataset_id , direction = "export" , events = (event ,),
15991640 )
16001641 return operation_id
16011642
0 commit comments