A check constraint violation is not mapped to the expected error code; uses fallback instead
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
Package and version
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
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from prisma/orm
-
bug/1-unconfirmed kind/bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
get-platform: distros with ID_LIKE=alpine are not detected as musl, so glibc engines are used on Alpine-based imagesPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
prisma/orm#31281 · 1 comment ·
Maintainers usually reply within 1 day
-
adapter-pg: connectToShadowDb connects to the main database when built from a connection stringMay be free again @cestercian claimed this 10 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
prisma/orm#31196 · 1 comment ·
Maintainers usually reply within 1 day
-
[Prisma 8] Type-check time grows exponentially with chained .include() callsPossibly taken @SiKreuz claimed this 13 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
prisma/orm#31161 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
prisma/orm#31125 · 4 comments · 6 reactions ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
tenstorrent/ttnn-visualizer#2526 ·
Maintainers usually reply within 1 day
-
trySessionCache calls /get-session twice when minting session_data (cache miss or expired cookie)Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
neondatabase/neon-js#301 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
tashfeenahmed/freellmapi#2305 ·
Maintainers usually reply within 1 day