From 3b599508a32b843b44d98c0f334f5ef315cf24a4 Mon Sep 17 00:00:00 2001 From: dal Date: Thu, 1 May 2025 10:06:14 -0600 Subject: [PATCH] hotfix datasource id ref --- .../handlers/src/metrics/get_metric_data_handler.rs | 12 +----------- .../src/metrics/get_metric_for_dashboard_handler.rs | 6 +----- api/libs/handlers/src/metrics/get_metric_handler.rs | 8 ++------ api/libs/handlers/src/metrics/types.rs | 6 ++++-- 4 files changed, 8 insertions(+), 24 deletions(-) diff --git a/api/libs/handlers/src/metrics/get_metric_data_handler.rs b/api/libs/handlers/src/metrics/get_metric_data_handler.rs index fb46b6f42..44eaecf10 100644 --- a/api/libs/handlers/src/metrics/get_metric_data_handler.rs +++ b/api/libs/handlers/src/metrics/get_metric_data_handler.rs @@ -146,17 +146,7 @@ pub async fn get_metric_data_handler( let sql = metric_yml.sql; // --- USE DIRECT DATA SOURCE ID --- - let data_source_id = match Uuid::parse_str(&metric.data_source_id) { - Ok(id) => id, - Err(_) => { - tracing::error!( - "Invalid data_source_id format ({}) found for metric {}", - metric.data_source_id, - request.metric_id - ); - return Err(anyhow!("Invalid data source ID associated with the metric")); - } - }; + let data_source_id = metric.data_source_id; // Already a Uuid tracing::debug!(metric_id = %request.metric_id, data_source_id = %data_source_id, "Using direct data source ID from metric"); tracing::info!( diff --git a/api/libs/handlers/src/metrics/get_metric_for_dashboard_handler.rs b/api/libs/handlers/src/metrics/get_metric_for_dashboard_handler.rs index c1e8b37d2..c9a02ff92 100644 --- a/api/libs/handlers/src/metrics/get_metric_for_dashboard_handler.rs +++ b/api/libs/handlers/src/metrics/get_metric_for_dashboard_handler.rs @@ -168,7 +168,6 @@ pub async fn get_metric_for_dashboard_handler( // Get dataset information for the resolved dataset IDs (using the fetched IDs) let mut datasets = Vec::new(); - let mut first_data_source_id = None; if !resolved_dataset_ids.is_empty() { // Fetch only if there are IDs to prevent unnecessary query let dataset_infos = datasets::table @@ -187,9 +186,6 @@ pub async fn get_metric_for_dashboard_handler( id: dataset_info.id.to_string(), name: dataset_info.name, }); - if first_data_source_id.is_none() { - first_data_source_id = Some(dataset_info.data_source_id); - } } } @@ -278,7 +274,7 @@ pub async fn get_metric_for_dashboard_handler( file_name: metric_file.file_name, time_frame: resolved_time_frame, datasets, - data_source_id: first_data_source_id.map_or("".to_string(), |id| id.to_string()), + data_source_id: metric_file.data_source_id, // Use canonical Uuid from main record error: None, // Assume ok chart_config: Some(resolved_chart_config), data_metadata, diff --git a/api/libs/handlers/src/metrics/get_metric_handler.rs b/api/libs/handlers/src/metrics/get_metric_handler.rs index 883cb3bef..1219b3694 100644 --- a/api/libs/handlers/src/metrics/get_metric_handler.rs +++ b/api/libs/handlers/src/metrics/get_metric_handler.rs @@ -286,7 +286,6 @@ pub async fn get_metric_handler( // Get dataset information for the resolved dataset IDs let mut datasets = Vec::new(); - let mut first_data_source_id = None; // Fetch datasets based on the resolved_dataset_ids fetched above if !resolved_dataset_ids.is_empty() { let dataset_infos = datasets::table @@ -305,9 +304,6 @@ pub async fn get_metric_handler( id: dataset_info.id.to_string(), name: dataset_info.name, }); - if first_data_source_id.is_none() { - first_data_source_id = Some(dataset_info.data_source_id); - } } } @@ -420,8 +416,8 @@ pub async fn get_metric_handler( description: resolved_description, // Use resolved description file_name: metric_file.file_name, // Not versioned time_frame: resolved_time_frame, // Use resolved time frame - datasets, // Fetched based on resolved_dataset_ids - data_source_id: first_data_source_id.map_or("".to_string(), |id| id.to_string()), // Based on resolved datasets + datasets, // Fetched based on resolved_dataset_ids (for display purposes only) + data_source_id: metric_file.data_source_id, // Use canonical ID (Uuid) from main record error: None, // Assume ok chart_config: Some(resolved_chart_config), // Use resolved chart config data_metadata, // Not versioned diff --git a/api/libs/handlers/src/metrics/types.rs b/api/libs/handlers/src/metrics/types.rs index 75216ff52..7c6b2ec60 100644 --- a/api/libs/handlers/src/metrics/types.rs +++ b/api/libs/handlers/src/metrics/types.rs @@ -3,6 +3,8 @@ use database::{enums::{AssetPermissionRole, Verification}, types::{ChartConfig, use serde::{Deserialize, Serialize}; use uuid::Uuid; use std::collections::HashMap; +use diesel::Selectable; +use serde_json::Value; #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Dataset { @@ -34,8 +36,8 @@ pub struct BusterMetric { pub file_name: String, pub time_frame: String, pub datasets: Vec, - pub data_source_id: String, - pub error: Option, + pub data_source_id: Uuid, + pub error: Option, pub chart_config: Option, // BusterChartConfigProps pub data_metadata: Option, pub status: Verification,