diff --git a/apps/sim/lib/table/import.test.ts b/apps/sim/lib/table/import.test.ts index 812d2b59ad3..8872f987d61 100644 --- a/apps/sim/lib/table/import.test.ts +++ b/apps/sim/lib/table/import.test.ts @@ -74,6 +74,17 @@ describe('import', () => { ) expect(columns.map((c) => c.type)).toEqual(['string', 'number']) }) + + it('keeps integers past the safe range as text so no digit is rounded away', () => { + const { columns } = inferSchemaFromCsv( + ['discord_id', 'quantity'], + [ + { discord_id: '1234567890123456789', quantity: '9007199254740991' }, + { discord_id: '987654321098765432', quantity: '-12' }, + ] + ) + expect(columns.map((c) => c.type)).toEqual(['string', 'number']) + }) }) describe('coerceValue', () => { diff --git a/apps/sim/lib/table/import.ts b/apps/sim/lib/table/import.ts index 3738669530f..e73e0a72e1b 100644 --- a/apps/sim/lib/table/import.ts +++ b/apps/sim/lib/table/import.ts @@ -389,10 +389,17 @@ export function inferColumnType(values: unknown[]): InferredCsvColumnType { if (nonEmpty.length === 0) return 'string' // A leading zero before another digit marks a code (ZIP, phone, SKU), not a - // quantity: storing it as a number would drop the zero for good. + // quantity: storing it as a number would drop the zero for good. So does an + // integer past 2^53 (snowflake ids, long account numbers): a number + // column would round away its last digits. const allNumber = nonEmpty.every((v) => { const s = String(v).trim() - return s !== '' && !Number.isNaN(Number(s)) && !/^[+-]?0\d/.test(s) + return ( + s !== '' && + !Number.isNaN(Number(s)) && + !/^[+-]?0\d/.test(s) && + !(/^[+-]?\d+$/.test(s) && !Number.isSafeInteger(Number(s))) + ) }) if (allNumber) return 'number'