Skip to content

fix(postgrest): count rows in the configured schema - #1021

Merged
Tr00d merged 1 commit into
masterfrom
fix/postgrest-count-schema-header
Dec 2, 2026
Merged

Tr00d merged 1 commit into
masterfrom
fix/postgrest-count-schema-header

Conversation

@Tr00d

@Tr00d Tr00d commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Count() now counts rows in the schema set by ClientOptions.Schema. Before this fix it always counted the server's default schema whenever another schema was configured.

This is a behavior change. A count on a client configured for a non-default schema now returns that schema's count. Before, it returned the count of the same-named table in the default schema, or failed when the default schema had no such table.

What was wrong

Count() is sent as HEAD. Helpers.PrepareRequestHeaders sent Accept-Profile only for GET and sent Content-Profile for every other method, HEAD included. PostgREST reads the schema of a GET or HEAD request from Accept-Profile (Switching schemas), so it ignored the header and used the default schema.

Confirmed on the local stack (personal is exposed in supabase/config.toml):

Request Response Content-Profile
HEAD /users with Accept-Profile: personal personal
HEAD /users with Content-Profile: personal (the old behavior) public

leroyjenkins exists only in personal.users. With Schema = "personal", Count filtered on that name returned 0 before this fix and returns 1 after it.

Behavior

  • GET and HEAD send the configured schema as Accept-Profile.
  • POST, PATCH, PUT and DELETE send it as Content-Profile, as before.
  • No public API change and no capability annotation change.

Tests

Tier Class Pins
E2E SchemaTests Count with Schema = "personal" counts the row that exists only in personal
Contract SchemaProfileTests a count sends the schema as Accept-Profile and sends no Content-Profile

Diff coverage: 100% (2 lines). Mutation: 8/8 killed on changed lines, 0 survivors.

@Tr00d
Tr00d marked this pull request as ready for review December 2, 2026 07:31
@Tr00d
Tr00d merged commit 71eb62e into master Dec 2, 2026
11 checks passed
@Tr00d
Tr00d deleted the fix/postgrest-count-schema-header branch December 2, 2026 07:31
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.

1 participant