@@ -94,6 +94,58 @@ def ret_checks(context: AssetExecutionContext):
9494 assert direct_results
9595
9696
97+ def test_materialize_result_check_targets_current_materialization ():
98+ with dg .instance_for_test () as instance :
99+
100+ @dg .asset (check_specs = [dg .AssetCheckSpec (name = "my_check" , asset = dg .AssetKey ("my_asset" ))])
101+ def my_asset (context : AssetExecutionContext ):
102+ return dg .MaterializeResult (
103+ check_results = [dg .AssetCheckResult (check_name = "my_check" , passed = True )]
104+ )
105+
106+ # First materialization
107+ result1 = dg .materialize ([my_asset ], instance = instance )
108+ assert result1 .success
109+
110+ # Get first check evaluation
111+ check_evals1 = result1 .get_asset_check_evaluations ()
112+ assert len (check_evals1 ) == 1
113+ check_eval1 = check_evals1 [0 ]
114+
115+ # Get first materialization
116+ mat_record1 = instance .fetch_materializations (my_asset .key , limit = 1 ).records [0 ]
117+
118+ # Verify first check references first materialization
119+ assert check_eval1 .target_materialization_data is not None
120+ assert check_eval1 .target_materialization_data .storage_id == mat_record1 .storage_id
121+ assert check_eval1 .target_materialization_data .run_id == result1 .run_id
122+
123+ # Second materialization
124+ result2 = dg .materialize ([my_asset ], instance = instance )
125+ assert result2 .success
126+
127+ # Get second check evaluation
128+ check_evals2 = result2 .get_asset_check_evaluations ()
129+ assert len (check_evals2 ) == 1
130+ check_eval2 = check_evals2 [0 ]
131+
132+ # Get second materialization (most recent)
133+ mat_record2 = instance .fetch_materializations (my_asset .key , limit = 1 ).records [0 ]
134+
135+ # Verify we have a *new* materialization (different storage_id)
136+ assert mat_record2 .storage_id != mat_record1 .storage_id
137+
138+ # Second check must reference *second* materialization, not first
139+ assert check_eval2 .target_materialization_data is not None
140+ assert check_eval2 .target_materialization_data .storage_id == mat_record2 .storage_id , (
141+ "Check from run 2 should reference materialization from run 2, not run 1. "
142+ )
143+ assert check_eval2 .target_materialization_data .storage_id != mat_record1 .storage_id , (
144+ "Check should not reference old materialization"
145+ )
146+ assert check_eval2 .target_materialization_data .run_id == result2 .run_id
147+
148+
97149def test_multi_asset ():
98150 @dg .multi_asset (outs = {"one" : dg .AssetOut (), "two" : dg .AssetOut ()})
99151 def outs_multi_asset ():
0 commit comments