Repository navigation
fix(adapter-pg): handle both quoted/unquoted column names in ColumnNotFound error - #29307
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds tests covering multiple PostgreSQL ColumnNotFound (42703) message variants and updates mapDriverError to extract the column via a regex capture with conditional unquoting (handles escaped double quotes) instead of token splitting. Changes
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Improves adapter-pg’s mapping of Postgres 42703 (“undefined column”) errors so the adapter can consistently extract the column identifier from error messages whether the identifier is quoted or not, and extends the unit tests accordingly.
Changes:
- Updated
mapDriverErrorto parseColumnNotFoundcolumn identifiers by removing double quotes. - Added a new unit test for unquoted
42703messages and clarified the existing quoted-case test.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/adapter-pg/src/errors.ts | Adjusts 42703 parsing to support unquoted column identifiers. |
| packages/adapter-pg/src/tests/errors.test.ts | Adds coverage for unquoted 42703 column names and renames the quoted-case test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/adapter-pg/src/__tests__/errors.test.ts (1)
129-147:⚠️ Potential issue | 🟡 MinorAdd a regression for the qualified-name form from the bug report.
These cases only cover bare identifiers. The reported failure path was the qualified form, so the suite can still miss regressions on
table.foo/ quoted qualified names unless one of those message shapes is exercised here.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 35c8ff41-c036-463d-99fc-d83a7f426ff5
📒 Files selected for processing (2)
packages/adapter-pg/src/__tests__/errors.test.tspackages/adapter-pg/src/errors.ts
39f63c3 to
1f1e905
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: b1a62681-6b36-4156-8e13-c36510c8cdb0
📒 Files selected for processing (1)
packages/adapter-pg/src/__tests__/errors.test.ts
833f2e4 to
6a62d9c
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 8567d834-0e4e-4a22-b0ca-20f15f5c37d2
📒 Files selected for processing (2)
packages/adapter-pg/src/__tests__/errors.test.tspackages/adapter-pg/src/errors.ts
6a62d9c to
2e1f2ad
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 2b4d51ae-2b5a-481f-a348-f83a53d2e21b
📒 Files selected for processing (2)
packages/adapter-pg/src/__tests__/errors.test.tspackages/adapter-pg/src/errors.ts
|
Hey @jacek-prisma could you please approve GA jobs? |
…ix ColumnNotFound for unquoted names
PostgreSQL NOT NULL violations (23502) populate `error.column` with the
violating column name. The `error.detail` field contains
"Failing row contains (...)" — not the "Key (...)" format used by
unique-violation (23505) — so the regex that was used never matched,
causing `meta.target` to always be empty ([]) for P2011 errors.
Fix by reading `error.column` directly, consistent with adapter-pg.
For ColumnNotFound (42703), the old implementation
(`error.message.split(' ').at(1)?.split('"').at(1)`) only handled
quoted column names. The improved regex
(`/^column (.+) does not exist$/`) handles unquoted names, qualified
names, and escaped quotes, matching what adapter-pg already does since
prisma#29307.
Adds an errors.test.ts covering all cases for both error codes.
…umnNotFound (#29737) Postgres reports a missing column in more than one way. The identifier is quoted only when it needs to be, and it can be qualified with the table name: ``` column foo does not exist column "foo" does not exist column users.first_name does not exist column "users"."first name" does not exist ``` `adapter-ppg` splits the message on double quotes, which only handles the second form. The unquoted forms produce `undefined`, and an identifier containing spaces is truncated at the first space, so `P2022` ends up without a usable column name. The same bug was fixed in `adapter-pg` in #29307. This applies the same parsing to `adapter-ppg` and adds the test cases from that fix, which the package did not have before.
…umnNotFound (prisma#29737) Postgres reports a missing column in more than one way. The identifier is quoted only when it needs to be, and it can be qualified with the table name: ``` column foo does not exist column "foo" does not exist column users.first_name does not exist column "users"."first name" does not exist ``` `adapter-ppg` splits the message on double quotes, which only handles the second form. The unquoted forms produce `undefined`, and an identifier containing spaces is truncated at the first space, so `P2022` ends up without a usable column name. The same bug was fixed in `adapter-pg` in prisma#29307. This applies the same parsing to `adapter-ppg` and adds the test cases from that fix, which the package did not have before.
This pull request improves the handling and testing of PostgreSQL "ColumnNotFound" errors in the adapter. The main focus is on correctly extracting column names from error messages, regardless of whether the column name is quoted, and ensuring the tests cover both scenarios.
We were getting "The column
(not available)does not exist in the current database" error all the time, the sql was trying to get qualified name (e.g. schema.table_name) which generated postgres error message without quotes:column table.column does not existvscolumn "column" does not exist.Our setup included:
Error handling improvements:
mapDriverErrorfunction inerrors.tsto strip quotes from column names when parsing "ColumnNotFound" (42703) errors, ensuring consistent extraction of the column name.Testing enhancements:
errors.test.ts, ensuring both cases are covered for "ColumnNotFound" errors.Summary by CodeRabbit
Bug Fixes
Tests