Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclear error on big decimal value insert in transaction #11381

Closed
steebchen opened this issue Jan 25, 2022 · 1 comment
Closed

Unclear error on big decimal value insert in transaction #11381

steebchen opened this issue Jan 25, 2022 · 1 comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: BigInt scalar type `BigInt`

Comments

@steebchen
Copy link
Contributor

steebchen commented Jan 25, 2022

Bug description

An unclear error message:

called `Option::unwrap()` on a `None` value

is returned when attempting to insert a very big decimal value (bigger than the database allows) in a transaction.

How to reproduce

// remove all balances first to make sure balances which are missing in a newer update are deleted
rm := r.db.Balance.FindMany(
	db.Balance.AccountID.Equals(account.ID),
).Delete().Tx()

ops = append(ops, rm)

for _, balance := range balances {
	if balance.amount.IsNegative() {
		log.Printf("wallet balance is negative, ignoring. balance id: %s. account id %s", balance.id, account.ID)
		continue
	}
	tx := r.db.Balance.CreateOne(
		db.Balance.ID.Set(r.id.Generate()),
		db.Balance.Amount.Set(balance.amount),
		db.Balance.Account.Link(
			db.Account.ID.Equals(account.ID),
		),
		db.Balance.Asset.Link(
			db.Asset.ID.Equals(balance.id),
		),
	).Tx()
	ops = append(ops, tx)
}

if err := r.db.Prisma.Transaction(ops...).Exec(ctx); err != nil {
	return fmt.Errorf("balance insert: %w", err)
}

results in

{"timestamp":"2022-01-25T09:38:29.608076Z","level":"ERROR","fields":{"message":"PANIC","reason":"called `Option::unwrap()` on a `None` value","file":"/Users/runner/.cargo/git/checkouts/quaint-9f01e008b9a89c14/85bb6a1/src/connector/postgres/conversion/decimal.rs","line":81,"column":39},"target":"query_engine"}

because in one of the values the decimal is very big

`balances` payload
[
  {
    "ID": "23GbW5U6VCdIvS8R3JQD",
    "Amount": "1.4823749237489237"
  },
  {
    "ID": "23GcDOFK15cnI4UOC0KB",
    "Amount": "5"
  },
  {
    "ID": "24BUAUvMquUppi40KCdn",
    "Amount": "175726212731318740000000000000000000000000000000000000000000"
  }
]

Expected behavior

Should have a clear error message, like that the value is too big.

Prisma information

/// Balance
model balance {
  id         String   @id
  created_at DateTime @default(now())
  updated_at DateTime @updatedAt
  amount     Decimal  // <- this is numberic(64, 30) in the db
  comment    String[]

  account_id String
  account    account @relation(fields: [account_id], references: [id])

  asset_id String
  asset    asset  @relation(fields: [asset_id], references: [id])

  // ensure a unique constraint on the combination of asset_id and account_id for continuous upserts
  @@unique([account_id, asset_id])
}

Environment & setup

  • OS:
  • Database: PostgreSQL 13.4 on x86_64-pc-linux-musl, compiled by gcc (Alpine 10.3.1_git20210424) 10.3.1 20210424, 64-bit
  • Node.js version:

Go client v0.13.0 which is prisma@3.8.1

Prisma Version

Environment variables loaded from .env
prisma                : 3.8.1
@prisma/client        : Not found
Current platform      : darwin
Query Engine (Binary) : query-engine 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at ../../../Library/Caches/prisma/binaries/cli/3.8.1/34df67547cf5598f5a6cd3eb45f14ee70c3fb86f/prisma-query-engine-darwin, resolved by PRISMA_QUERY_ENGINE_BINARY)
Migration Engine      : migration-engine-cli 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at ../../../Library/Caches/prisma/binaries/cli/3.8.1/34df67547cf5598f5a6cd3eb45f14ee70c3fb86f/prisma-migration-engine-darwin, resolved by PRISMA_MIGRATION_ENGINE_BINARY)
Introspection Engine  : introspection-core 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at ../../../Library/Caches/prisma/binaries/cli/3.8.1/34df67547cf5598f5a6cd3eb45f14ee70c3fb86f/prisma-introspection-engine-darwin, resolved by PRISMA_INTROSPECTION_ENGINE_BINARY)
Format Binary         : prisma-fmt 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at ../../../Library/Caches/prisma/binaries/cli/3.8.1/34df67547cf5598f5a6cd3eb45f14ee70c3fb86f/prisma-prisma-fmt-darwin, resolved by PRISMA_FMT_BINARY)
Default Engines Hash  : 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f
Studio                : 0.452.0
Go client @ v0.13.0
@steebchen steebchen added the kind/bug A reported bug. label Jan 25, 2022
@janpio janpio added the team/client Issue for team Client. label Jan 25, 2022
@pantharshit00 pantharshit00 added bug/2-confirmed Bug has been reproduced and confirmed. topic: BigInt scalar type `BigInt` labels Feb 7, 2022
@dpetrick
Copy link
Contributor

Duplicate of: #11312

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: BigInt scalar type `BigInt`
Projects
None yet
Development

No branches or pull requests

4 participants