From 7322d72e636cf5d8e2beeab0b179fd70cff24645 Mon Sep 17 00:00:00 2001 From: Rahul Barwal Date: Fri, 9 May 2025 12:03:54 +0530 Subject: [PATCH] fix: enhance datasource structure retrieval in useTableOrSpreadsheet hook (#40612) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Problem App was crashing when the data source configuration was undefined or in an error state. Root cause The code attempted to access properties from an undefined data source config (e.g., MongoDB), leading to runtime errors. Solution This PR handles adding an optional check before accessing the data source config to prevent crashes when the config is undefined or in an error state. Fixes #`Issue Number` _or_ Fixes `Issue URL` > [!WARNING] > _If no issue exists, please create an issue first, and check with the maintainers if the issue is valid._ ## Automation /ok-to-test tags="@tag.JSONForm, @tag.PropertyPane, @tag.GenerateCRUD, @tag.Datasource, @tag.Sanity, @tag.Widget" ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: bcd0f9d2d009bcf07bb10afda1a30ff1a93bc9ae > Cypress dashboard. > Tags: `@tag.JSONForm, @tag.PropertyPane, @tag.GenerateCRUD, @tag.Datasource, @tag.Sanity, @tag.Widget` > Spec: >
Thu, 08 May 2025 13:32:39 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No ## Summary by CodeRabbit - **Bug Fixes** - Improved stability when accessing data source tables, preventing potential errors if data source information is missing. --- .../TableOrSpreadsheetDropdown/useTableOrSpreadsheet.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/client/src/components/editorComponents/WidgetQueryGeneratorForm/CommonControls/TableOrSpreadsheetDropdown/useTableOrSpreadsheet.tsx b/app/client/src/components/editorComponents/WidgetQueryGeneratorForm/CommonControls/TableOrSpreadsheetDropdown/useTableOrSpreadsheet.tsx index 4dfbbaa984..5e2400ca4c 100644 --- a/app/client/src/components/editorComponents/WidgetQueryGeneratorForm/CommonControls/TableOrSpreadsheetDropdown/useTableOrSpreadsheet.tsx +++ b/app/client/src/components/editorComponents/WidgetQueryGeneratorForm/CommonControls/TableOrSpreadsheetDropdown/useTableOrSpreadsheet.tsx @@ -87,7 +87,7 @@ export function useTableOrSpreadsheet() { }, })); } else if (isMongoDBPluginDS(selectedDatasourcePluginPackageName)) { - return (datasourceStructure.tables || []).map((table) => ({ + return (datasourceStructure?.tables || []).map((table) => ({ id: table.name, label: table.name, value: table.name, @@ -97,7 +97,7 @@ export function useTableOrSpreadsheet() { disabled: false, })); } else if (datasourceStructure) { - return (datasourceStructure.tables || []).map((table) => { + return (datasourceStructure?.tables || []).map((table) => { const hasPrimaryKeys = tableHasPrimaryKeys(table); return {