This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch default_chart_settings
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 5d01f84805205b0c0d1bf1c8bf1247fcbc605be1
Author: Maxime Beauchemin <maximebeauche...@gmail.com>
AuthorDate: Sun Aug 3 19:47:04 2025 -0700

    debug: Add comprehensive logging for Chart Defaults data flow
    
    Added debug logs to trace how chart defaults flow through the system:
    
    DatasourceEditor.jsx:
    - Log onDatasourcePropChange calls with attr and value
    - Log updated datasource.extra after setState
    - Log what gets sent to modal via onDatasourceChange
    
    DatasourceModal.tsx:
    - Log what data.extra is received in onDatasourceChange callback
    - Log what currentDatasource.extra gets set to
    - Log currentDatasource.extra right before save
    
    This will help identify exactly where chart defaults data gets lost
    in the DatasourceEditor → DatasourceModal → API save flow.
    
    🤖 Generated with [Claude Code](https://claude.ai/code)
    
    Co-Authored-By: Claude <nore...@anthropic.com>
---
 .../src/components/Datasource/DatasourceEditor.jsx | 33 ++++++++++++++++++----
 .../src/components/Datasource/DatasourceModal.tsx  | 24 ++++++++++++++--
 .../ReportModal/HeaderReportDropdown/index.tsx     | 11 --------
 3 files changed, 50 insertions(+), 18 deletions(-)

diff --git a/superset-frontend/src/components/Datasource/DatasourceEditor.jsx 
b/superset-frontend/src/components/Datasource/DatasourceEditor.jsx
index 26e30b219e..9535749705 100644
--- a/superset-frontend/src/components/Datasource/DatasourceEditor.jsx
+++ b/superset-frontend/src/components/Datasource/DatasourceEditor.jsx
@@ -79,11 +79,15 @@ const extensionsRegistry = getExtensionsRegistry();
 
 // Helper function to safely parse extra field
 const parseExtra = extra => {
+  console.log('parseExtra called with:', extra, typeof extra);
   if (!extra) return {};
   if (typeof extra === 'object') return extra;
   try {
-    return JSON.parse(extra);
+    const parsed = JSON.parse(extra);
+    console.log('parseExtra parsed JSON:', parsed);
+    return parsed;
   } catch {
+    console.log('parseExtra failed to parse JSON, returning empty object');
     return {};
   }
 };
@@ -631,9 +635,15 @@ const ResultTable =
 class DatasourceEditor extends PureComponent {
   constructor(props) {
     super(props);
+    console.log(
+      'DatasourceEditor constructor - props.datasource.extra:',
+      props.datasource.extra,
+      typeof props.datasource.extra,
+    );
     this.state = {
       datasource: {
         ...props.datasource,
+        extra: props.datasource.extra || '{}', // Initialize null extra as 
empty JSON object
         owners: props.datasource.owners.map(owner => ({
           value: owner.value || owner.id,
           label: owner.label || `${owner.first_name} ${owner.last_name}`,
@@ -711,19 +721,29 @@ class DatasourceEditor extends PureComponent {
   }
 
   onDatasourceChange(datasource, callback = this.validateAndChange) {
+    console.log(
+      'onDatasourceChange sending to modal - datasource.extra:',
+      datasource.extra,
+    );
     this.setState({ datasource }, callback);
   }
 
   onDatasourcePropChange(attr, value) {
+    console.log(`onDatasourcePropChange: ${attr} =`, value);
     if (value === undefined) return; // if value is undefined do not update 
state
     const datasource = { ...this.state.datasource, [attr]: value };
     this.setState(
       prevState => ({
         datasource: { ...prevState.datasource, [attr]: value },
       }),
-      attr === 'table_name'
-        ? this.onDatasourceChange(datasource, this.tableChangeAndSyncMetadata)
-        : this.onDatasourceChange(datasource, this.validateAndChange),
+      () => {
+        console.log('Updated datasource.extra:', this.state.datasource.extra);
+        if (attr === 'table_name') {
+          this.onDatasourceChange(datasource, this.tableChangeAndSyncMetadata);
+        } else {
+          this.onDatasourceChange(datasource, this.validateAndChange);
+        }
+      },
     );
   }
 
@@ -1077,12 +1097,15 @@ class DatasourceEditor extends PureComponent {
                     ?.default_metric
                 }
                 onChange={value => {
+                  console.log('Setting default_metric to:', value);
                   const extra = { ...parseExtra(datasource.extra) };
                   if (!extra.default_chart_metadata) {
                     extra.default_chart_metadata = {};
                   }
                   extra.default_chart_metadata.default_metric = value;
-                  this.onDatasourcePropChange('extra', JSON.stringify(extra));
+                  const stringified = JSON.stringify(extra);
+                  console.log('Saving extra as:', stringified);
+                  this.onDatasourcePropChange('extra', stringified);
                 }}
                 placeholder={t('Select a metric')}
                 allowClear
diff --git a/superset-frontend/src/components/Datasource/DatasourceModal.tsx 
b/superset-frontend/src/components/Datasource/DatasourceModal.tsx
index cb78a538e4..3556830b16 100644
--- a/superset-frontend/src/components/Datasource/DatasourceModal.tsx
+++ b/superset-frontend/src/components/Datasource/DatasourceModal.tsx
@@ -106,6 +106,11 @@ const DatasourceModal: 
FunctionComponent<DatasourceModalProps> = ({
   const dialog = useRef<any>(null);
   const [modal, contextHolder] = Modal.useModal();
   const buildPayload = (datasource: Record<string, any>) => {
+    console.log(
+      'buildPayload - datasource.extra:',
+      datasource.extra,
+      typeof datasource.extra,
+    );
     const payload: Record<string, any> = {
       table_name: datasource.table_name,
       database_id: datasource.database?.id,
@@ -182,6 +187,10 @@ const DatasourceModal: 
FunctionComponent<DatasourceModalProps> = ({
   };
   const onConfirmSave = async () => {
     // Pull out extra fields into the extra object
+    console.log(
+      'Before save - currentDatasource.extra:',
+      currentDatasource.extra,
+    );
     setIsSaving(true);
     const overrideColumns = datasource.sql !== currentDatasource.sql;
     try {
@@ -193,6 +202,11 @@ const DatasourceModal: 
FunctionComponent<DatasourceModalProps> = ({
       const { json } = await SupersetClient.get({
         endpoint: `/api/v1/dataset/${currentDatasource?.id}`,
       });
+      console.log(
+        'After save GET - json.result.extra:',
+        json.result.extra,
+        typeof json.result.extra,
+      );
       addSuccessToast(t('The dataset has been saved'));
       // eslint-disable-next-line no-param-reassign
       json.result.type = 'table';
@@ -228,13 +242,19 @@ const DatasourceModal: 
FunctionComponent<DatasourceModalProps> = ({
   };
 
   const onDatasourceChange = (data: DatasetObject, err: Array<any>) => {
-    setCurrentDatasource({
+    console.log('DatasourceModal received - data.extra:', data.extra);
+    const newDatasource = {
       ...data,
       metrics: data?.metrics.map((metric: DatasetObject['metrics'][0]) => ({
         ...metric,
         is_certified: metric?.certified_by || metric?.certification_details,
       })),
-    });
+    };
+    console.log(
+      'DatasourceModal setting currentDatasource.extra to:',
+      newDatasource.extra,
+    );
+    setCurrentDatasource(newDatasource);
     setErrors(err);
   };
 
diff --git 
a/superset-frontend/src/features/reports/ReportModal/HeaderReportDropdown/index.tsx
 
b/superset-frontend/src/features/reports/ReportModal/HeaderReportDropdown/index.tsx
index ad80f98205..b370333d83 100644
--- 
a/superset-frontend/src/features/reports/ReportModal/HeaderReportDropdown/index.tsx
+++ 
b/superset-frontend/src/features/reports/ReportModal/HeaderReportDropdown/index.tsx
@@ -87,17 +87,6 @@ export const useHeaderReportMenuItems = ({
     const resourceTypeReports = reportsState[resourceType] || {};
     const reportData = resourceTypeReports[resourceId];
 
-    // Debug logging to understand what's happening
-    console.log('Report selector called:', {
-      resourceId,
-      resourceType,
-      reportsState: Object.keys(reportsState),
-      resourceTypeReports: Object.keys(resourceTypeReports),
-      reportData: reportData
-        ? { id: reportData.id, name: reportData.name }
-        : null,
-    });
-
     return reportData || null;
   });
 

Reply via email to