Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Add fix for spreadsheet import utils when infering boolean type column

Joshen Lim287926d80247
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.utils.ts b/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.utils.ts
index 4ba1a2c91b3..508fa4e5db2 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.utils.ts
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.utils.ts
@@ -123,7 +123,7 @@ export const inferColumnType = (column: string, rows: object[]) => {
// Infer boolean type
if (includes(['true', 'false'], columnData.toString().toLowerCase())) {
const isAllBoolean = columnDataAcrossRows.every((item: any) =>
- includes(['true', 'false'], item.toString().toLowerCase())
+ includes(['true', 'false'], (item || '').toString().toLowerCase())
)
if (isAllBoolean) {
return 'boolean'
diff --git a/studio/tests/components/Editor/SpreadsheetImport.utils.test.js b/studio/tests/components/Editor/SpreadsheetImport.utils.test.js
index a9d49688477..230fc76df53 100644
--- a/studio/tests/components/Editor/SpreadsheetImport.utils.test.js
+++ b/studio/tests/components/Editor/SpreadsheetImport.utils.test.js
@@ -35,6 +35,15 @@ describe('SpreadsheedImport.utils: inferColumnType', () => {
const type2 = inferColumnType('isRetired', mockData2)
expect(type2).toBe('boolean')
})
+ test('should infer text type for a supposed boolean column if one of the rows has a null value', () => {
+ const mockData3 = [
+ { name: 'bob', height: '161.72', isRetired: 'false' },
+ { name: 'bob', height: '161.72', isRetired: 'true' },
+ { name: 'bob', height: '161.72', isRetired: null },
+ ]
+ const type3 = inferColumnType('isRetired', mockData3)
+ expect(type3).toBe('text')
+ })
test('should infer objects as jsonb types correctly', () => {
const mockData = [{ name: 'bob', metadata: '{}' }]
const type = inferColumnType('metadata', mockData)