From a6e36a8bfecb9ebe6c7b135b9e01557f7ebc3e58 Mon Sep 17 00:00:00 2001 From: soryu Date: Sat, 31 Jan 2026 22:17:31 +0000 Subject: Fix null handling for deliverables in create_template_for_owner (#51) The previous code used `.unwrap_or_default()` which could produce `Some(Value::Null)` if JSON serialization failed, leading to inconsistent handling when the database returned NULL and sqlx attempted to decode with the `#[sqlx(json)]` attribute on an Option type. Changed to use `.ok()` which properly returns `None` when serialization fails, ensuring consistent NULL handling between the application and database layer. Fixes: "Failed to create template: error occurred while decoding column 'deliverables': unexpected null; try decoding as an Option" Co-authored-by: Claude Opus 4.5 --- makima/src/db/repository.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'makima') diff --git a/makima/src/db/repository.rs b/makima/src/db/repository.rs index 9fc2c84..8c7ea23 100644 --- a/makima/src/db/repository.rs +++ b/makima/src/db/repository.rs @@ -2163,7 +2163,10 @@ pub async fn create_template_for_owner( .bind(&req.description) .bind(serde_json::to_value(&req.phases).unwrap_or_default()) .bind(&req.default_phase) - .bind(req.deliverables.as_ref().map(|d| serde_json::to_value(d).unwrap_or_default())) + .bind(match &req.deliverables { + Some(d) => serde_json::to_value(d).ok(), + None => None, + }) .fetch_one(pool) .await } -- cgit v1.2.3