fix: trace-profile API SQL errors (missing FROM alias + null decoding)
Two pre-existing bugs broke rename/get operations:
1. schema.rs: DO UPDATE referenced 'tp' alias from LEFT JOIN which is
invisible in ON CONFLICT scope → 'missing FROM-clause entry for table tp'
Fix: use {tp_table}.column instead of tp.column
2. profile.rs: SELECT tp.properties / tn.properties can be NULL when no
trace_profile row exists but decoder expected non-optional Value
→ 'unexpected null; try decoding as an Option'
Fix: decode as Option<serde_json::Value> and handle None in merge logic
This commit is contained in:
@@ -56,15 +56,15 @@ pub async fn upsert_trace_profile(
|
||||
LEFT JOIN {tkg_table} tn ON tn.file_uuid = $1 \
|
||||
AND tn.node_type = 'face_track' AND (tn.properties->>'trace_id')::int = $2 \
|
||||
LEFT JOIN {tp_table} tp ON tp.file_uuid = $1 AND tp.trace_id = $2 \
|
||||
ON CONFLICT (file_uuid, trace_id) \
|
||||
DO UPDATE SET name = EXCLUDED.name{update_props}, \
|
||||
start_frame = COALESCE(EXCLUDED.start_frame, tp.start_frame), \
|
||||
end_frame = COALESCE(EXCLUDED.end_frame, tp.end_frame), \
|
||||
frame_count = COALESCE(EXCLUDED.frame_count, tp.frame_count), \
|
||||
key_frame = COALESCE(EXCLUDED.key_frame, tp.key_frame), \
|
||||
key_face = COALESCE(EXCLUDED.key_face, tp.key_face), \
|
||||
avg_confidence = COALESCE(EXCLUDED.avg_confidence, tp.avg_confidence), \
|
||||
updated_at = NOW()",
|
||||
ON CONFLICT (file_uuid, trace_id) \
|
||||
DO UPDATE SET name = EXCLUDED.name{update_props}, \
|
||||
start_frame = COALESCE(EXCLUDED.start_frame, {tp_table}.start_frame), \
|
||||
end_frame = COALESCE(EXCLUDED.end_frame, {tp_table}.end_frame), \
|
||||
frame_count = COALESCE(EXCLUDED.frame_count, {tp_table}.frame_count), \
|
||||
key_frame = COALESCE(EXCLUDED.key_frame, {tp_table}.key_frame), \
|
||||
key_face = COALESCE(EXCLUDED.key_face, {tp_table}.key_face), \
|
||||
avg_confidence = COALESCE(EXCLUDED.avg_confidence, {tp_table}.avg_confidence), \
|
||||
updated_at = NOW()",
|
||||
);
|
||||
|
||||
let mut query = sqlx::query(&sql).bind(file_uuid).bind(trace_id).bind(name);
|
||||
|
||||
Reference in New Issue
Block a user