@@ -15,6 +15,7 @@ use std::collections::{
1515use sqlx:: {
1616 Postgres ,
1717 QueryBuilder ,
18+ types:: Json ,
1819} ;
1920use uuid:: Uuid ;
2021
@@ -251,11 +252,11 @@ pub(crate) async fn bulk_insert_case_blobs(
251252 b. push_bind ( & row. case_hash )
252253 . push_bind ( & row. task_type )
253254 . push_bind ( & row. case_group )
254- . push_bind ( & row. input_payload )
255- . push_bind ( & row. expected_output )
256- . push_bind ( & row. context_payload )
257- . push_bind ( & row. tags )
258- . push_bind ( & row. metadata ) ;
255+ . push_bind ( Json ( row. input_payload . clone ( ) ) )
256+ . push_bind ( Json ( row. expected_output . clone ( ) ) )
257+ . push_bind ( Json ( row. context_payload . clone ( ) ) )
258+ . push_bind ( Json ( row. tags . clone ( ) ) )
259+ . push_bind ( Json ( row. metadata . clone ( ) ) ) ;
259260 } ) ;
260261
261262 query_builder. push ( " ON CONFLICT (case_hash) DO NOTHING" ) ;
@@ -739,6 +740,41 @@ mod tests {
739740 assert_eq ! ( rows, vec![ ( 0 , "open" . to_string( ) ) , ( 1 , "open" . to_string( ) ) ] ) ;
740741 }
741742
743+ #[ sqlx:: test( migrations = "../migrations" ) ]
744+ #[ ignore = "requires a PostgreSQL DATABASE_URL for sqlx migration tests" ]
745+ async fn bulk_insert_case_blobs_preserves_json_null_context ( pool : PgPool ) {
746+ let case_blob = CaseBlobDraft {
747+ case_hash : format ! ( "case-{}" , Uuid :: now_v7( ) ) ,
748+ task_type : "classification" . to_string ( ) ,
749+ case_group : None ,
750+ input_payload : serde_json:: json!( { "text" : "hello" } ) ,
751+ expected_output : serde_json:: Value :: Null ,
752+ context_payload : serde_json:: Value :: Null ,
753+ tags : serde_json:: json!( [ ] ) ,
754+ metadata : serde_json:: json!( { } ) ,
755+ } ;
756+
757+ let mut tx = pool. begin ( ) . await . unwrap ( ) ;
758+ bulk_insert_case_blobs ( & mut tx, std:: slice:: from_ref ( & case_blob) )
759+ . await
760+ . unwrap ( ) ;
761+ tx. commit ( ) . await . unwrap ( ) ;
762+
763+ let context_payload = sqlx:: query_scalar :: < _ , serde_json:: Value > (
764+ r#"
765+ SELECT context_payload
766+ FROM case_blobs
767+ WHERE case_hash = $1
768+ "# ,
769+ )
770+ . bind ( & case_blob. case_hash )
771+ . fetch_one ( & pool)
772+ . await
773+ . unwrap ( ) ;
774+
775+ assert_eq ! ( context_payload, serde_json:: Value :: Null ) ;
776+ }
777+
742778 #[ sqlx:: test( migrations = "../migrations" ) ]
743779 #[ ignore = "requires a PostgreSQL DATABASE_URL for sqlx migration tests" ]
744780 async fn bulk_insert_shard_placements_inserts_distinct_active_shards ( pool : PgPool ) {
0 commit comments