Skip to content

fix(adapter-pg): handle both quoted/unquoted column names in ColumnNotFound error - #29307

Merged
jacek-prisma merged 2 commits into
prisma:mainfrom
CyanoFresh:alex/fix-quoted-column-message
Mar 17, 2026
Merged

jacek-prisma merged 2 commits into
prisma:mainfrom
CyanoFresh:alex/fix-quoted-column-message

Conversation

@CyanoFresh

@CyanoFresh CyanoFresh commented Mar 6, 2026 •

Copy link
Copy Markdown
Contributor

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 exist vs column "column" does not exist.
Our setup included:

  • multi-schema DB
  • custom @@Map() fields.
  • Postgres v18.3

Error handling improvements:

  • Updated the mapDriverError function in errors.ts to strip quotes from column names when parsing "ColumnNotFound" (42703) errors, ensuring consistent extraction of the column name.

Testing enhancements:

  • Added a new test case for handling unquoted column names and clarified the description of the existing test for quoted column names in errors.test.ts, ensuring both cases are covered for "ColumnNotFound" errors.

Summary by CodeRabbit

  • Bug Fixes

    • Improved detection and normalization of PostgreSQL "column not found" errors so column names are identified correctly for unquoted, quoted, qualified, spaced, and escaped-quote formats, providing clearer, consistent error details.
  • Tests

    • Added comprehensive tests covering many column-name formats to ensure accurate detection and unchanged original error messaging.

@coderabbitai

coderabbitai Bot commented Mar 6, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds 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

Cohort / File(s) Summary
ColumnNotFound Error Tests
packages/adapter-pg/src/__tests__/errors.test.ts
Adds multiple test cases for SQL error code 42703 covering unquoted, quoted, qualified, space-containing, and escaped-quote column name formats; asserts kind = ColumnNotFound, parsed column, and preserves originalCode/originalMessage.
ColumnNotFound Error Implementation
packages/adapter-pg/src/errors.ts
Replaces token-splitting extraction with a regex-based capture of the column segment in mapDriverError for code 42703; when captured value is quoted, removes surrounding quotes and unescapes doubled quotes ("" -> ").
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: improving how the adapter handles both quoted and unquoted column names in ColumnNotFound errors, which matches the core fix in errors.ts and test additions.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@CLAassistant

CLAassistant commented Mar 6, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CyanoFresh
CyanoFresh marked this pull request as ready for review March 6, 2026 10:24
Copilot AI review requested due to automatic review settings March 6, 2026 10:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 mapDriverError to parse ColumnNotFound column identifiers by removing double quotes.
  • Added a new unit test for unquoted 42703 messages 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.

Comment thread packages/adapter-pg/src/errors.ts Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🟡 Minor

Add 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9fa295d and 69b5b51.

📒 Files selected for processing (2)
  • packages/adapter-pg/src/__tests__/errors.test.ts
  • packages/adapter-pg/src/errors.ts

Comment thread packages/adapter-pg/src/errors.ts Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: b1a62681-6b36-4156-8e13-c36510c8cdb0

📥 Commits

Reviewing files that changed from the base of the PR and between 1f1e905 and 833f2e4.

📒 Files selected for processing (1)
  • packages/adapter-pg/src/__tests__/errors.test.ts

@CyanoFresh
CyanoFresh force-pushed the alex/fix-quoted-column-message branch from 833f2e4 to 6a62d9c Compare March 11, 2026 18:55

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8567d834-0e4e-4a22-b0ca-20f15f5c37d2

📥 Commits

Reviewing files that changed from the base of the PR and between 833f2e4 and 6a62d9c.

📒 Files selected for processing (2)
  • packages/adapter-pg/src/__tests__/errors.test.ts
  • packages/adapter-pg/src/errors.ts

Comment thread packages/adapter-pg/src/errors.ts Resolved
@CyanoFresh
CyanoFresh force-pushed the alex/fix-quoted-column-message branch from 6a62d9c to 2e1f2ad Compare March 11, 2026 19:16

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2b4d51ae-2b5a-481f-a348-f83a53d2e21b

📥 Commits

Reviewing files that changed from the base of the PR and between 6a62d9c and 2e1f2ad.

📒 Files selected for processing (2)
  • packages/adapter-pg/src/__tests__/errors.test.ts
  • packages/adapter-pg/src/errors.ts

Comment thread packages/adapter-pg/src/errors.ts Resolved
@CyanoFresh
CyanoFresh requested a review from jacek-prisma March 11, 2026 19:35
@CyanoFresh

Copy link
Copy Markdown
Contributor Author

Hey @jacek-prisma could you please approve GA jobs?

@jacek-prisma
jacek-prisma merged commit 33667c3 into prisma:main Mar 17, 2026
249 of 251 checks passed
@CyanoFresh
CyanoFresh deleted the alex/fix-quoted-column-message branch March 17, 2026 16:57
matingathani added a commit to matingathani/prisma that referenced this pull request Apr 17, 2026
…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.
aqrln pushed a commit that referenced this pull request Jul 20, 2026
…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.
lh0x00 pushed a commit to lh0x00/prisma that referenced this pull request Aug 9, 2026
…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.
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.

4 participants