Skip to content

fix(postgrest): correct self-reference inference#2525

Merged
mandarini merged 2 commits into
supabase:masterfrom
7ttp:fix/postgrest-self-referencing-column-embed
Jul 15, 2026
Merged

fix(postgrest): correct self-reference inference#2525
mandarini merged 2 commits into
supabase:masterfrom
7ttp:fix/postgrest-self-referencing-column-embed

Conversation

@7ttp

@7ttp 7ttp commented Jul 15, 2026

Copy link
Copy Markdown
Member

TL;DR

Extends #2520 to cover the remaining direct column self reference case in 2.110.6-canary.0

parents:parent(*) works at runtime but was still typed as SelectQueryError
when multiple self referencing FKs exist

Direct column matches now resolve correctly while real table name ambiguity errors remain covered

ref

@7ttp
7ttp requested review from a team as code owners July 15, 2026 09:15
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cd356655-39a6-4861-88c7-8ad2a1f24cd7

📥 Commits

Reviewing files that changed from the base of the PR and between cfa9501 and 246c565.

⛔ Files ignored due to path filters (1)
  • packages/core/postgrest-js/test/types.generated.ts is excluded by !**/*.generated.*
📒 Files selected for processing (3)
  • packages/core/postgrest-js/test/relationships.test.ts
  • packages/core/postgrest-js/test/supabase/migrations/00000000000000_schema.sql
  • packages/core/postgrest-js/test/supabase/seed.sql

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved resolution for embedded relationships when multiple self-referential foreign keys exist, avoiding false “ambiguous” results for column-based matches.
    • Relationship conflicts are still reported when genuinely ambiguous, guiding users to disambiguate as before.
  • Tests
    • Added coverage for self-referential embedding with an aliased embed path and multiple matching foreign keys, including expected error behavior and typed outcomes.
  • Chores
    • Extended test schema and seed data to support the new relationship scenarios.

Walkthrough

Reverse relationship resolution now treats column-matched relations as unambiguous and returns them directly, alongside the existing hint-based shortcut. Relationship tests add a self-referencing lab schema with multiple foreign keys, seed related rows, and verify that an aliased column embed infers an array type while an ambiguous embed produces SelectQueryError.

Assessment against linked issues

Objective Addressed Explanation
Infer the correct array type for a self-referencing column-name hint [#2517]
Preserve the full foreign-key constraint hint at runtime [#2517] The changes only update type-level reverse-relationship resolution; no runtime select-string or hint serialization logic is changed.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


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.

@pkg-pr-new

pkg-pr-new Bot commented Jul 15, 2026

Copy link
Copy Markdown

Open in StackBlitz

@supabase/auth-js

npm i https://pkg.pr.new/@supabase/auth-js@2525

@supabase/functions-js

npm i https://pkg.pr.new/@supabase/functions-js@2525

@supabase/postgrest-js

npm i https://pkg.pr.new/@supabase/postgrest-js@2525

@supabase/realtime-js

npm i https://pkg.pr.new/@supabase/realtime-js@2525

@supabase/storage-js

npm i https://pkg.pr.new/@supabase/storage-js@2525

@supabase/supabase-js

npm i https://pkg.pr.new/@supabase/supabase-js@2525

commit: 246c565

@coveralls

coveralls commented Jul 15, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 93.143% (+12.6%) from 80.53% — 7ttp:fix/postgrest-self-referencing-column-embed into supabase:master

@mandarini mandarini 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.

Thank youuuu!!! :D

One thing I'd love to see before I merge: the new MultipleSelfReferencesDatabase type and lab table are hand-written and don't correspond to anything in our actual test database. Every other test in relationships.test.ts runs against the real schema in test/supabase/migrations/00000000000000_schema.sql, where collections only has a single self-referencing FK. The tests you added are compile-time only (the queries are built but never awaited), so nothing actually exercises this against a real PostgREST instance with two self-referencing FKs on the same table.

Would you be up for adding a second self-referencing FK to an existing table (or a small new one) in the migration, and turning at least the parents:parent(*) case into a runtime-executed test like the other self-reference tests in that file? That would give end-to-end confidence that this resolves the way we expect, not just that the types compile.

@7ttp

7ttp commented Jul 15, 2026

Copy link
Copy Markdown
Member Author

Thank youuuu!!! :D

One thing I'd love to see before I merge: the new MultipleSelfReferencesDatabase type and lab table are hand-written and don't correspond to anything in our actual test database. Every other test in relationships.test.ts runs against the real schema in test/supabase/migrations/00000000000000_schema.sql, where collections only has a single self-referencing FK. The tests you added are compile-time only (the queries are built but never awaited), so nothing actually exercises this against a real PostgREST instance with two self-referencing FKs on the same table.

Would you be up for adding a second self-referencing FK to an existing table (or a small new one) in the migration, and turning at least the parents:parent(*) case into a runtime-executed test like the other self-reference tests in that file? That would give end-to-end confidence that this resolves the way we expect, not just that the types compile.

absolutely! 💚🙂
added this in the latest commit: 246c565

@7ttp
7ttp requested a review from mandarini July 15, 2026 14:01
@mandarini
mandarini merged commit 5c18b62 into supabase:master Jul 15, 2026
26 checks passed
@7ttp
7ttp deleted the fix/postgrest-self-referencing-column-embed branch July 15, 2026 14:19
mandarini pushed a commit to supabase/ssr that referenced this pull request Jul 16, 2026
This PR updates `@supabase/supabase-js` to v2.110.7.

**Source**: supabase-js-stable-release

---

## Release Notes

## v2.110.7

## 2.110.7 (2026-07-16)

### 🩹 Fixes

- **postgrest:** correct self-reference inference
([#2525](supabase/supabase-js#2525))
- **realtime:** trigger set auth on INITIAL_SESSION event
([#2531](supabase/supabase-js#2531))
- **realtime:** update phoenix to fix presence issue
([#2532](supabase/supabase-js#2532))

### ❤️ Thank You

- Eduardo Gurgel
- Filipe Cabaço @filipecabaco
- Vaibhav @7ttp

This PR was created automatically.

Co-authored-by: supabase-workflow-trigger[bot] <266661614+supabase-workflow-trigger[bot]@users.noreply.github.com>
mandarini pushed a commit to supabase/supabase that referenced this pull request Jul 22, 2026
This PR updates @supabase/*-js libraries to version 2.110.8.

**Source**: supabase-js-stable-release

**Changes**:
- Updated @supabase/supabase-js to 2.110.8
- Updated @supabase/auth-js to 2.110.8
- Updated @supabase/realtime-js to 2.110.8
- Updated @supabase/postgest-js to 2.110.8
- Refreshed pnpm-lock.yaml

---

## Release Notes

## v2.110.8

## 2.110.8 (2026-07-21)

### 🩹 Fixes

- **auth:** downgrade aborted/transient fetch failures from
console.error to warn
([#2544](supabase/supabase-js#2544))
- **functions:** clean up cross-signal abort listener on invoke() return
([#2487](supabase/supabase-js#2487))
- **functions:** match response Content-Type case-insensitively
([#2515](supabase/supabase-js#2515))
- **storage:** url-encode object key in CDN purge methods
([#2545](supabase/supabase-js#2545))
- **supabase:** skip Node warning in Deno
([#2541](supabase/supabase-js#2541))

### ❤️ Thank You

- Franco Kaddour @FrancoKaddour
- Katerina Skroumpelou @mandarini
- Pedro Henrique
- Vaibhav @7ttp
## v2.110.7

## 2.110.7 (2026-07-16)

### 🩹 Fixes

- **postgrest:** correct self-reference inference
([#2525](supabase/supabase-js#2525))
- **realtime:** trigger set auth on INITIAL_SESSION event
([#2531](supabase/supabase-js#2531))
- **realtime:** update phoenix to fix presence issue
([#2532](supabase/supabase-js#2532))

### ❤️ Thank You

- Eduardo Gurgel
- Filipe Cabaço @filipecabaco
- Vaibhav @7ttp

This PR was created automatically.

Co-authored-by: supabase-workflow-trigger[bot] <266661614+supabase-workflow-trigger[bot]@users.noreply.github.com>
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.

Self-referencing FK hint: _fkey suffix truncated at runtime, wrong types with column hint

3 participants