3232 store_imported_dataset as store_normative_dataset ,
3333)
3434from .catalog_verification import verify_catalog_relations
35+ from .database_urls import require_persistent_database_url
3536
3637_IDENTIFIER = re .compile (r"[^a-zA-Z0-9_]+" )
3738
@@ -669,12 +670,20 @@ def initialize_wide_catalog(
669670) -> dict [str , Any ]:
670671 """Initialize or verify the singular normative OpenStatSpec catalog."""
671672 validate_connection_url (database_url )
672- profile , _active = effective_profile (
673+ require_persistent_database_url (database_url )
674+ profile , active = effective_profile (
673675 database_url , dolt_conformance_source = dolt_conformance_source ,
674676 )
675677 engine = create_engine (database_url )
676678 normative = normative_catalog (MetaData ())
677- with engine .begin () as connection :
679+ audit_relations = {
680+ normative .fidelity_event .name ,
681+ normative .operation .name ,
682+ }
683+ with _bound_catalog_transaction (
684+ engine = engine , profile_name = profile .name , active = active ,
685+ audit_relations = audit_relations , phase = "catalog initialization" ,
686+ ) as connection :
678687 inspector = inspect (connection )
679688 views = set (inspector .get_view_names ())
680689 if views and not inspector .has_table (normative .catalog_identity .name ):
@@ -755,8 +764,9 @@ def create_wide_dataset(
755764 dolt_conformance_source : Any | None = None ,
756765) -> dict [str , Any ]:
757766 del source_table_name , source_created_at , source_modified_at
767+ require_persistent_database_url (database_url )
758768 validate_connection_url (database_url )
759- profile , _active_connection = (
769+ profile , active_connection = (
760770 effective_profile (database_url )
761771 if dolt_conformance_source is None
762772 else effective_profile (
@@ -765,7 +775,14 @@ def create_wide_dataset(
765775 )
766776 engine = create_engine (database_url )
767777 normative = normative_catalog (MetaData ())
768- with engine .begin () as catalog_connection :
778+ audit_relations = {
779+ normative .fidelity_event .name ,
780+ normative .operation .name ,
781+ }
782+ with _bound_catalog_transaction (
783+ engine = engine , profile_name = profile .name , active = active_connection ,
784+ audit_relations = audit_relations , phase = "catalog initialization" ,
785+ ) as catalog_connection :
769786 catalog_existed = inspect (catalog_connection ).has_table (
770787 normative .catalog_identity .name
771788 )
@@ -827,7 +844,10 @@ def create_wide_dataset(
827844 with engine .begin () as setup :
828845 _verify_normative_catalog (setup , normative )
829846 namespace_owned = True
830- with engine .begin () as connection :
847+ with _bound_catalog_transaction (
848+ engine = engine , profile_name = profile .name , active = active_connection ,
849+ audit_relations = audit_relations , phase = "import" ,
850+ ) as connection :
831851 if connection .execute (
832852 select (normative .dataset .c .dataset_id ).where (or_ (
833853 normative .dataset .c .dataset_name == dataset_id ,
@@ -1333,7 +1353,7 @@ def record_export_operation(
13331353 dolt_conformance_source : Any | None = None ,
13341354) -> str :
13351355 """Persist a completed export only in the normative audit catalog."""
1336- del destination , operation_details
1356+ operation_details = dict ( operation_details or {})
13371357 engine = create_engine (database_url )
13381358 effective_profile (
13391359 database_url , dolt_conformance_source = dolt_conformance_source ,
@@ -1354,14 +1374,26 @@ def record_export_operation(
13541374 record_normative_fidelity_events (
13551375 connection , normative , operation_id = operation_id ,
13561376 dataset_id = str (dataset ["dataset_id" ]), direction = "export" ,
1357- events = ({
1358- ** event ,
1359- "severity" : event .get ("severity" , "warning" ),
1360- "details" : {
1361- ** event .get ("details" , {}),
1362- "accepted_by_user" : True ,
1363- },
1364- } for event in events ),
1377+ events = (
1378+ * (
1379+ {
1380+ ** event ,
1381+ "severity" : event .get ("severity" , "warning" ),
1382+ "details" : {
1383+ ** event .get ("details" , {}),
1384+ "accepted_by_user" : True ,
1385+ },
1386+ }
1387+ for event in events
1388+ ),
1389+ * (({
1390+ "code" : "operation-engine-identity" ,
1391+ "detail" : "Export engine identity recorded for audit." ,
1392+ "severity" : "info" ,
1393+ "source_item" : destination ,
1394+ "details" : operation_details ,
1395+ },) if operation_details else ()),
1396+ ),
13651397 )
13661398 return operation_id
13671399
0 commit comments