Skip to content

Negative number cannot be entered as string to Decimal input #5508

@livthomas

Description

@livthomas

Bug description

I'm trying to create a new record in an SQLite table where one of the fields is of type Decimal. If I pass a negative number as string to create function, I get the following error from Prisma:

Argument initialBalance: Got invalid value '-65.7' on prisma.createOneCashBox. Provided String, expected Decimal.

It works if I pass it the same value as number or Decimal. Positive string values also work without any problems.

How to reproduce

Steps to reproduce the behavior:

  1. Define a table with Decimal field.
  2. Try to pass a negative string value when creating a new record in this table (e.g. -65.7).
  3. See error in the output.

Expected behavior

The input type looks like this:

export interface CashBoxCreateInput {
  ...
  initialBalance: Decimal | number | string
  ...
}

So I would assume Prisma should be able to process any numeric value entered as either string, number or Decimal when creating a new record with Decimal field.

Prisma information

generator client {
  provider = "prisma-client-js"
  previewFeatures = ["nativeTypes"]
}

datasource db {
  provider = "sqlite"
  url      = "file:../myfile.db"
}

model CashBox {
  id                  Int      @default(autoincrement()) @id
  ...
  initialBalance      Decimal 
  ...
}

Environment & setup

  • OS: Manjaro Linux
  • Database: SQLite
  • Node.js version: 15.6.0
  • Prisma version: 2.16.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions