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

Some errors are obfuscated by interactive transactions when using binary engine #12862

Closed
Tracked by #12363
driimus opened this issue Apr 18, 2022 · 2 comments · Fixed by #15684
Closed
Tracked by #12363

Some errors are obfuscated by interactive transactions when using binary engine #12862

driimus opened this issue Apr 18, 2022 · 2 comments · Fixed by #15684
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/engines Issue for tech Engines. topic: client api topic: error topic: interactiveTransactions
Milestone

Comments

@driimus
Copy link

driimus commented Apr 18, 2022

Bug description

Runtime errors such as CHECK constraint failures are obfuscated by interactive transactions when engineType = "binary", making it impossible to appropriately handle rejected transactions.

Only tested this with postgres so far.

Note that the library engine does not seem to have the same issue. CI output comparing both engine types: https://github.com/driimus/prisma-interactive-tx-errors/actions/runs/2184082955

How to reproduce

  1. Clone https://github.com/driimus/prisma-interactive-tx-errors
  2. Run the tests locally using a binary engine
  3. Notice that the test using an interactive transaction fails due to a nondescript error.

Expected behavior

The original error / error message should be surfaced, similar to the library engine's behavior.

Expected:

ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(DbError { severity: \"ERROR\", parsed_severity: Some(Error), code: SqlState(\"23514\"), message: \"new row for relation \\\"Post\\\" violates check constraint \\\"Post_viewCount_check\\\"\", detail: Some(\"Failing row contains (1, 2022-04-18 12:42:07.239, 2022-04-18 12:42:07.239, Minima nulla ea., null, f, -1, 1).\"), hint: None, position: None, where_: None, schema: Some(\"public\"), table: Some(\"Post\"), column: None, datatype: None, constraint: Some(\"Post_viewCount_check\"), file: Some(\"execMain.c\"), line: Some(2003), routine: Some(\"ExecConstraints\") }) }) })"

Received:

 ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(DbError { severity: \"ERROR\", parsed_severity: Some(Error), code: SqlState(\"25P02\"), message: \"current transaction is aborted, commands ignored until end of transaction block\", detail: None, hint: None, position: None, where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some(\"postgres.c\"), line: Some(1718), routine: Some(\"exec_bind_message\") }) }) })"

Prisma information

Minimal reproduction repo

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["interactiveTransactions"]
  engineType      = "binary"
}

datasource db {
  provider = "postgres"
  url      = "postgresql://postgres:example@localhost"
}

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}

model Post {
  id        Int      @id @default(autoincrement())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  title     String
  content   String?
  published Boolean  @default(false)
  viewCount Int      @default(0)
  author    User?    @relation(fields: [authorId], references: [id])
  authorId  Int?
}

Environment & setup

  • OS: Ubuntu 20.04.4 LTS
  • Database: PostgreSQL
  • Node.js version: 16.14.2

Prisma Version

prisma                  : 3.12.0
@prisma/client          : 3.12.0
Current platform        : debian-openssl-1.1.x
Query Engine (Node-API) : libquery-engine 22b822189f46ef0dc5c5b503368d1bee01213980 (at node_modules/.pnpm/@prisma+engines@3.12.0-37.22b822189f46ef0dc5c5b503368d1bee01213980/node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
Migration Engine        : migration-engine-cli 22b822189f46ef0dc5c5b503368d1bee01213980 (at node_modules/.pnpm/@prisma+engines@3.12.0-37.22b822189f46ef0dc5c5b503368d1bee01213980/node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine    : introspection-core 22b822189f46ef0dc5c5b503368d1bee01213980 (at node_modules/.pnpm/@prisma+engines@3.12.0-37.22b822189f46ef0dc5c5b503368d1bee01213980/node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary           : prisma-fmt 22b822189f46ef0dc5c5b503368d1bee01213980 (at node_modules/.pnpm/@prisma+engines@3.12.0-37.22b822189f46ef0dc5c5b503368d1bee01213980/node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash    : 22b822189f46ef0dc5c5b503368d1bee01213980
Studio                  : 0.459.0
@driimus driimus added the kind/bug A reported bug. label Apr 18, 2022
@garrensmith garrensmith added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. team/client Issue for team Client. topic: client api topic: interactiveTransactions labels Apr 20, 2022
@janpio janpio added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. topic: error process/candidate and removed bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. labels Apr 20, 2022
@millsp millsp mentioned this issue May 5, 2022
10 tasks
@janpio janpio assigned janpio and unassigned garrensmith Sep 15, 2022
@janpio janpio added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Sep 15, 2022
@janpio
Copy link
Member

janpio commented Sep 15, 2022

Thanks for the great reproduction @driimus (as usual 🙇), I can indeed reproduce this, both with the original version and with updated Prisma: driimus/prisma-interactive-tx-errors#2

An additional note:
Even the "expected" error above might not actually be fully expected, as it does not look like a known Prisma error but something far more unstructured. That would deserve additional investigation by running the tests from the reproduction manually and comparing from the output when you run this outside of transactions. (Of course the outcome of that might be that this generally does not work as expected - which would be even more meh.)

@danstarns
Copy link
Contributor

The reason this is happening is due to the fact that this:

CHECK ("viewCount" >= 0),

Has been added to the migration file, and because of the fact that it's not something that Prisma generates we don't have the logic to handle it.

We are looking into propagating all of those errors.

aqrln added a commit that referenced this issue Nov 23, 2022
…socket errors (#15684)

Only retry network-related errors in BinaryEngine, and only if those didn't occur during a write operation.

Fixes: #12862
Co-authored-by: Alexey Orlenko <alex@aqrln.net>
@Jolg42 Jolg42 added this to the 4.7.0 milestone Nov 24, 2022
jkomyno pushed a commit that referenced this issue Dec 21, 2022
…socket errors (#15684)

Only retry network-related errors in BinaryEngine, and only if those didn't occur during a write operation.

Fixes: #12862
Co-authored-by: Alexey Orlenko <alex@aqrln.net>
jkomyno pushed a commit that referenced this issue Dec 21, 2022
…socket errors (#15684)

Only retry network-related errors in BinaryEngine, and only if those didn't occur during a write operation.

Fixes: #12862
Co-authored-by: Alexey Orlenko <alex@aqrln.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment