You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
adapter-pg: mapDriverError drops error.constraint for 23505 but uses it for 23503 #29495
@prisma/adapter-pg's mapDriverError treats error.constraint (populated by node-postgres from PG_DIAG_CONSTRAINT_NAME) asymmetrically between the unique-violation and foreign-key-violation branches.
Reference: @prisma/[email protected]/dist/index.mjs, function mapDriverError:
The 23505 branch ignores error.constraint entirely. @prisma/adapter-mysql preserves it as constraint.index on 1062 (see #29344), so Postgres is the outlier here.
Why this matters
For partial unique indexes the column list is ambiguous. Two unique constraints on the same table can share key columns — e.g. one full unique on (user_id, account_id) and one partial unique on (account_id) WHERE role = 'owner'. Both surface as 23505, and the current mapping produces identical constraint.fields for both, so callers can't tell which constraint fired without regex-matching originalMessage (which per #28281 is not public API).
Suggested fix
Preserve the constraint name when it's present, matching the shape the 23503 branch already uses:
The UniqueConstraintViolationMappedError type in @prisma/driver-adapter-utils already accepts { index: string } as a valid shape, so no public-API change is required.
Took a look — the fix is to mirror the 23503 branch's index: error.constraint fallback in the 23505 unique-violation branch. Partial unique indexes make the column-list alone ambiguous, and mysql already preserves it via #29344, so postgres is the odd one out. I'll send a PR.
Activity
BootstrapperSBL commentedon Apr 23, 2026
Took a look — the fix is to mirror the 23503 branch's
index: error.constraintfallback in the 23505 unique-violation branch. Partial unique indexes make the column-list alone ambiguous, and mysql already preserves it via #29344, so postgres is the odd one out. I'll send a PR.fix(adapter-pg): preserve constraint name for unique violations (23505)
fix(adapter-pg): preserve constraint name for unique violations (2350…
fix(adapter-pg): preserve constraint name for unique violations (2350…