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

fix(client): Errors are obfuscated by interactive transactions gh-12862 #15602

Closed
wants to merge 12 commits into from

Conversation

danstarns
Copy link
Contributor

@danstarns danstarns commented Sep 29, 2022

Closes: #12862

@danstarns danstarns requested review from a team and millsp and removed request for a team September 29, 2022 09:13
@danstarns danstarns changed the title test(client): Coverage for gh-12862 fix(client): Errors are obfuscated by interactive transactions gh-12862 Sep 29, 2022
@aqrln aqrln added this to the 4.5.0 milestone Sep 30, 2022
@danstarns
Copy link
Contributor Author

The best way to integrate and test an engines fix for this is to use the enginesOverride in your equivalent of:

/Users/danielstarns/code/clones/prisma/packages/fetch-engine/package.json
  "repository": {
    "type": "git",
    "url": "https://github.com/prisma/prisma.git",
    "directory": "packages/fetch-engine"
  },
  "bugs": "https://github.com/prisma/prisma/issues",
+  "enginesOverride": {
+    "folder": "/Users/danielstarns/code/clones/prisma-engines/target/release"
+  },
  "devDependencies": {

You can then build your rust branch that contains the fix, and do an pnpm i in the root of prisma/prisma.

Finally, you can now run the test suite that is in this branch.

cd ./packages/client
PRISMA_CLIENT_ENGINE_TYPE="binary" pnpm run test:functional:code 12862

You should expect one test to fail until the fix is applied to engines.

Current:

FAIL  tests/functional/issues/12862/tests.ts
  issues.12862 (provider=postgresql)
    ✓ should propagate the correct error when a method fails (339 ms)
    ✓ should propagate the correct error when a method fails inside an transaction (19 ms)
    ✕ should propagate the correct error when a method fails inside an interactive transaction (173 ms)

  ● issues.12862 (provider=postgresql) › should propagate the correct error when a method fails inside an interactive transaction

    expect(received).rejects.toThrowError(expected)

    Expected substring: "violates check constraint \\\"post_viewcount_check\\\""
    Received message:   "
    Invalid `client.post.create()` invocation in
    /Users/danielstarns/code/clones/prisma/packages/client/tests/functional/issues/12862/tests.ts:63:42·
      60   },
      61 })
      62·
    → 63 const post = await client.post.create(
    Error occurred during query execution:
    ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(DbError { severity: \"ERROR\", parsed_severity: Some(Error), code: SqlState(E25P02), 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(1591), routine: Some(\"exec_bind_message\") }) }) })"

          30853 |       throw new PrismaClientRustPanicError(message, this.client._clientVersion);
          30854 |     } else if (error2 instanceof PrismaClientUnknownRequestError) {
        > 30855 |       throw new PrismaClientUnknownRequestError(message, this.client._clientVersion);
                |             ^
          30856 |     } else if (error2 instanceof PrismaClientInitializationError) {
          30857 |       throw new PrismaClientInitializationError(message, this.client._clientVersion);
          30858 |     } else if (error2 instanceof PrismaClientRustPanicError) {

          at RequestHandler.handleRequestError (runtime/index.js:30855:13)
          at RequestHandler.handleRequestError [as request] (runtime/index.js:30834:12)
          at PrismaClient._request (runtime/index.js:31812:16)
          at tests/functional/issues/12862/tests.ts:63:24
          at Proxy._transactionWithCallback (runtime/index.js:31744:18)
          at Object.<anonymous> (tests/functional/issues/12862/tests.ts:54:7)

      71 |           return post
      72 |         }),
    > 73 |       ).rejects.toThrowError('violates check constraint \\"post_viewcount_check\\"')
         |                 ^
      74 |     })
      75 |   },
      76 |   {

      at Object.toThrowError (../../../../node_modules/.pnpm/expect@28.1.3/node_modules/expect/build/index.js:241:22)
      at Object.toThrowError (issues/12862/tests.ts:73:17)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 2 passed, 3 total
Snapshots:   0 total
Time:        4.271 s, estimated 8 s
Ran all test suites matching /12862/i.
 ELIFECYCLE  Command failed with exit code 1.

Expected

PASS  tests/functional/issues/12862/tests.ts
  issues.12862 (provider=postgresql)
    ✓ should propagate the correct error when a method fails (339 ms)
    ✓ should propagate the correct error when a method fails inside an transaction (19 ms)
    ✓ should propagate the correct error when a method fails inside an interactive transaction (173 ms)

@garrensmith
Copy link
Contributor

This issue is in the BinaryEngine in the client. On this line here:
https://github.com/prisma/prisma/blob/fix/12862/packages/engine-core/src/binary/BinaryEngine.ts#L970

We will retry a failed operation. This leads to the interactive transaction returning a different unexpected error than the actual error that caused the problem.

I'm not sure why we retry operations in the binary engine. I think this is a bad idea and we should not retry at all.
If there is a good reason for that, then we should not retry interactive transaction operations.

@danstarns danstarns enabled auto-merge (squash) October 31, 2022 23:35
@danstarns danstarns requested a review from millsp October 31, 2022 23:35
@danstarns
Copy link
Contributor Author

Waiting for merge of #15684

@janpio janpio modified the milestones: 4.6.0, 4.7.0 Nov 8, 2022
@danstarns
Copy link
Contributor Author

Merged into #15684

@danstarns danstarns closed this Nov 9, 2022
auto-merge was automatically disabled November 9, 2022 20:54

Pull request was closed

@Jolg42 Jolg42 deleted the fix/12862 branch May 10, 2023 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Some errors are obfuscated by interactive transactions when using binary engine
5 participants