@@ -7092,6 +7092,42 @@ def test_asset_check_partitioned_planned_and_evaluation(
70927092 assert latest_c [check_key ].partition == "c"
70937093 assert latest_c [check_key ].status == AssetCheckExecutionRecordStatus .PLANNED
70947094
7095+ # Test get_asset_check_partition_records - returns all partitions with latest status
7096+ partition_records = storage .get_asset_check_partition_records (check_key )
7097+ assert len (partition_records ) == 3
7098+
7099+ records_by_partition = {r .partition_key : r for r in partition_records }
7100+ assert set (records_by_partition .keys ()) == {"a" , "b" , "c" }
7101+
7102+ # Verify each partition has correct status
7103+ assert (
7104+ records_by_partition ["a" ].last_execution_status
7105+ == AssetCheckExecutionRecordStatus .SUCCEEDED
7106+ )
7107+ assert (
7108+ records_by_partition ["b" ].last_execution_status
7109+ == AssetCheckExecutionRecordStatus .FAILED
7110+ )
7111+ assert (
7112+ records_by_partition ["c" ].last_execution_status
7113+ == AssetCheckExecutionRecordStatus .PLANNED
7114+ )
7115+
7116+ # Verify all records have the same run_id (all planned in same run)
7117+ assert records_by_partition ["a" ].last_planned_run_id == run_id
7118+ assert records_by_partition ["b" ].last_planned_run_id == run_id
7119+ assert records_by_partition ["c" ].last_planned_run_id == run_id
7120+
7121+ # Verify last_event_id is set for all records (this is the row id in the table)
7122+ assert records_by_partition ["a" ].last_event_id is not None
7123+ assert records_by_partition ["b" ].last_event_id is not None
7124+ assert records_by_partition ["c" ].last_event_id is not None
7125+
7126+ filtered_records = storage .get_asset_check_partition_records (
7127+ check_key , after_event_storage_id = 999999
7128+ )
7129+ assert len (filtered_records ) == 0
7130+
70957131 def test_asset_check_partitioned_multiple_runs_same_partition (
70967132 self ,
70977133 storage : EventLogStorage ,
@@ -7107,22 +7143,54 @@ def test_asset_check_partitioned_multiple_runs_same_partition(
71077143 partitions_def = dg .StaticPartitionsDefinition (["a" ])
71087144 partitions_subset = partitions_def .subset_with_partition_keys (["a" ])
71097145
7110- # Run 1: Store planned + evaluation for partition "a" with passed=True
7146+ # Run 1: Store planned event for partition "a"
71117147 storage .store_event (
71127148 _create_check_planned_event (run_id_1 , check_key , partitions_subset = partitions_subset )
71137149 )
7150+
7151+ # status for partition "a" should be PLANNED
7152+ partition_records = storage .get_asset_check_partition_records (check_key )
7153+ assert len (partition_records ) == 1
7154+ record = partition_records [0 ]
7155+ assert record .partition_key == "a"
7156+ assert record .last_execution_status == AssetCheckExecutionRecordStatus .PLANNED
7157+ assert record .last_planned_run_id == run_id_1
7158+
7159+ # Run 1: Now store evaluation event for partition "a" with passed=True
71147160 storage .store_event (
71157161 _create_check_evaluation_event (run_id_1 , check_key , passed = True , partition = "a" )
71167162 )
71177163
7164+ # status for partition "a" should be SUCCEEDED
7165+ partition_records = storage .get_asset_check_partition_records (check_key )
7166+ assert len (partition_records ) == 1
7167+ record = partition_records [0 ]
7168+ assert record .partition_key == "a"
7169+ assert record .last_execution_status == AssetCheckExecutionRecordStatus .SUCCEEDED
7170+ assert record .last_planned_run_id == run_id_1
7171+
71187172 # Run 2: Store planned + evaluation for partition "a" with passed=False
71197173 storage .store_event (
71207174 _create_check_planned_event (run_id_2 , check_key , partitions_subset = partitions_subset )
71217175 )
7176+
7177+ # back to PLANNED
7178+ partition_records = storage .get_asset_check_partition_records (check_key )
7179+ record = partition_records [0 ]
7180+ assert record .last_execution_status == AssetCheckExecutionRecordStatus .PLANNED
7181+ assert record .last_planned_run_id == run_id_2
7182+
7183+ # Run 2: Now store evaluation event for partition "a" with passed=False
71227184 storage .store_event (
71237185 _create_check_evaluation_event (run_id_2 , check_key , passed = False , partition = "a" )
71247186 )
71257187
7188+ # onto FAILED
7189+ partition_records = storage .get_asset_check_partition_records (check_key )
7190+ record = partition_records [0 ]
7191+ assert record .last_execution_status == AssetCheckExecutionRecordStatus .FAILED
7192+ assert record .last_planned_run_id == run_id_2
7193+
71267194 # Verify get_asset_check_execution_history returns 2 records for partition "a"
71277195 checks = storage .get_asset_check_execution_history (check_key , limit = 10 , partition = "a" )
71287196 assert len (checks ) == 2
@@ -7149,6 +7217,16 @@ def test_asset_check_partitioned_multiple_runs_same_partition(
71497217 assert check_key in latest_overall
71507218 assert latest_overall [check_key ].run_id == run_id_2
71517219
7220+ # Test get_asset_check_partition_records returns only the latest record per partition
7221+ partition_records = storage .get_asset_check_partition_records (check_key )
7222+ assert len (partition_records ) == 1 # Only partition "a" exists
7223+
7224+ record = partition_records [0 ]
7225+ assert record .partition_key == "a"
7226+ # Should be the latest execution (run_id_2, FAILED)
7227+ assert record .last_execution_status == AssetCheckExecutionRecordStatus .FAILED
7228+ assert record .last_planned_run_id == run_id_2
7229+
71527230 def test_asset_check_partitioned_with_target_materialization (
71537231 self ,
71547232 storage : EventLogStorage ,
@@ -7237,6 +7315,17 @@ def test_asset_check_partitioned_with_target_materialization(
72377315 assert check_data .target_materialization_data .storage_id == m1_storage_id
72387316 assert check_data .target_materialization_data .storage_id != m2_storage_id
72397317
7318+ # Test get_asset_check_partition_records includes target_materialization_storage_id
7319+ partition_records = storage .get_asset_check_partition_records (check_key )
7320+ assert len (partition_records ) == 1
7321+
7322+ record = partition_records [0 ]
7323+ assert record .partition_key == "a"
7324+ assert record .last_execution_status == AssetCheckExecutionRecordStatus .SUCCEEDED
7325+ assert record .last_planned_run_id == run_id_1
7326+ # Verify materialization_event_storage_id matches M1
7327+ assert record .last_execution_target_materialization_storage_id == m1_storage_id
7328+
72407329
72417330def _create_check_planned_event (
72427331 run_id : str ,
0 commit comments