Skip to content

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

Closed

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

Activity

  1. added
    bug/1-unconfirmed
    on Feb 8, 2021
  2. added
    bug/2-confirmed
    and removed
    bug/1-unconfirmed
    on Feb 8, 2021
  3. pantharshit00 commented on Feb 8, 2021

    @pantharshit00
    Contributor

    I can confirm this. Looks like a bug in our string casting logic.

  4. added a commit that references this issue on Feb 9, 2021
    28c09a3
  5. added this to the 2.17.0 milestone on Feb 9, 2021
  6. Jolg42 commented on Feb 9, 2021

    @Jolg42
    Contributor

    Thanks a lot for reporting 🙏
    This issue is fixed in the latest dev version of @prisma/client.

    It will be part of the next 2.17.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/2-confirmedkind/bugtopic: native database types

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions