Skip to content

SQLite dialect: writing null to a nullable Decimal field crashes with "Cannot read properties of null (reading 'toString')" #2797

Description

@leon-mrks

Description

With the SQLite dialect (v3), any create/update that writes null to a nullable Decimal field crashes:

TypeError: Cannot read properties of null (reading 'toString')
 ❯ SqliteCrudDialect.transformInput src/client/crud/dialects/sqlite.ts:102:46
 ❯ CreateOperationHandler.create src/client/crud/operations/base.ts:454:55

Repro

model Project {
    id         String   @id @default(cuid())
    hourlyRate Decimal?
}
await db.project.create({ data: { hourlyRate: null } }); // throws

Cause

SqliteCrudDialect.transformInput only early-returns on undefined, and the Decimal branch calls .toString() unguarded (sqlite.ts:102):

case 'Decimal':
    return (value as Decimal).toString();

The Postgres dialect guards this same case:

value !== null ? value.toString() : value

Suggested fix

Mirror the Postgres guard in the SQLite dialect:

case 'Decimal':
    return value !== null ? (value as Decimal).toString() : value;

Affects at least 3.6.4 through 3.9.0; current main still has the unguarded call. Happy to send a PR if useful.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions