A check constraint violation is not mapped to the expected error code; uses fallback instead

Open
#31,215 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
mysql, sql, typescript
Domain
database

Research direction

Start with the error-mapping code that turns MySQL error codes into Prisma error codes, and find where the fallback P2039 is produced. Check how the MySQL check-constraint violation is classified there and where P2004 is expected. Run the MySQL check-constraint reproduction against a test table to confirm the code returned. Done when that violation surfaces as P2004 and the existing error tests still pass.

Written by the indexing model from the issue text.

Description

bug/1-unconfirmed kind/bug
Package and version

[email protected]

What happened?

A query that fails due to a check constraint violation will throw error code P2039 - an undocumented fallback error code, first introduced in this PR. This results in a generic error message:

Database error. Code: X. Message: Y

What did you expect to happen?

It should instead be mapped to P2004.

Minimal reproduction

Add a check constraint to a table and have it fail:

ADD CONSTRAINT test_table
  CHECK (test_table.val_a + test_table.val_b <= 1);
prisma.test_table.create({
  data: {
    val_a: 1,
    val_b: 1
  }
})
Environment
  • Database: MySQL 8.5
  • Node: 26.13.0
  • Prisma: 7.10.1
Additional context

This error has apparently never been mapped correctly, or at least, code P2004 has never been used since its creation/reservation in 2019 - Discord wmadden.

This behavior was also reported in issue #25562, before the fallback logic was introduced.

Dominant language
TypeScript
Stars
47.8k
Forks
2.6k
Avg merge
1d 21h
Merged PRs (30d)
227

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from prisma/orm

All issues in prisma/orm

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.