Skip to content

Commit 720b1d2

Browse files
committed
fix case blob context null mismatch
1 parent 2f778f4 commit 720b1d2

2 files changed

Lines changed: 47 additions & 10 deletions

File tree

vigilo/src/db/workflows/execution_processing.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use sqlx::{
2626
PgPool,
2727
Postgres,
2828
QueryBuilder,
29+
types::Json,
2930
};
3031
use tokio::task::{
3132
self,
@@ -794,12 +795,12 @@ async fn allocate_execution_attempts_for_cases(
794795
b.push_bind(row.case.case_id)
795796
.push_bind(&row.case.case_hash)
796797
.push_bind(&row.case.task_type)
797-
.push_bind(&row.tags)
798-
.push_bind(&row.input_payload)
799-
.push_bind(&row.expected_output)
800-
.push_bind(&row.case_metadata)
798+
.push_bind(Json(row.tags.clone()))
799+
.push_bind(Json(row.input_payload.clone()))
800+
.push_bind(Json(row.expected_output.clone()))
801+
.push_bind(Json(row.case_metadata.clone()))
801802
.push_bind(row.profile_group_id)
802-
.push_bind(&row.evaluator_manifest)
803+
.push_bind(Json(row.evaluator_manifest.clone()))
803804
.push_bind(row.expected_evaluator_count)
804805
.push_bind(row.input_ordinal);
805806
});

vigilo/src/db/workflows/run_create.rs

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::collections::{
1515
use sqlx::{
1616
Postgres,
1717
QueryBuilder,
18+
types::Json,
1819
};
1920
use 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

Comments
 (0)