-
-
Notifications
You must be signed in to change notification settings - Fork 168
Description
Bug report
I confirm this is a bug with Supabase, not with my own application.
I confirm I have searched the Docs, GitHub Discussions, and Discord.
Describe the bug
The endpoint GET /tables/:id returns 404 - Cannot find a table with ID {id} for ALL tables located in schemas other than public, even though these tables exist and are fully accessible via SQL and appear correctly in the table listing endpoint (GET /tables).
This bug was introduced in v0.91.0 and affects all subsequent versions through v0.93.1. The last working version is v0.84.2.
Impact: Supabase Studio becomes unusable for viewing/editing tables in custom schemas on self-hosted instances.
To Reproduce
Steps to reproduce the behavior:
Create a custom schema and table:
sql
CREATE SCHEMA directus;
CREATE TABLE directus.compras (
id serial PRIMARY KEY,
name text
);
Get the table's OID:
sql
SELECT oid, relname, relnamespace::regnamespace
FROM pg_class
WHERE relname = 'compras';
-- Result: oid = 127071, schema = directus
Test the list endpoint (works correctly):
bash
curl http://localhost:8080/tables?included_schemas=directus
Returns: Array including {"id": 127071, "name": "compras", "schema": "directus", ...}
Test the get-by-id endpoint (fails):
bash
curl http://localhost:8080/tables/127071
Returns: {"error": "Cannot find a table with ID 127071"}
Observe the same behavior for ANY table in non-public schemas:
Tables in public schema: ✅ Works
Tables in directus, custom, or any other schema: ❌ Returns 404
Expected behavior
GET /tables/:id should return the table details regardless of which schema it's in, since PostgreSQL OIDs are globally unique identifiers. The endpoint should work identically to v0.84.2.
Expected response:
json
{
"id": 127071,
"schema": "directus",
"name": "compras",
"columns": [...],
"primary_keys": [...],
"relationships": [...]
}
Screenshots
N/A - This is an API endpoint bug, but the Studio shows this error when trying to open any table in a custom schema:
Error: Cannot find a table with ID 127071
System information
OS: Ubuntu 24.04 LTS
Browser: N/A (API endpoint issue, affects Studio)
Version of postgres-meta: v0.93.1 (bug present in v0.91.0+)
PostgreSQL Version: 15.8
Deployment: Self-hosted (Docker Compose)
Affected versions:
❌ v0.93.1, v0.93.0
❌ v0.92.0
❌ v0.91.0 through v0.91.7
✅ v0.84.2 (last working version)
Additional context
Root Cause Analysis
I've identified the exact cause in src/lib/PostgresMetaTables.ts:
Version v0.84.2 (WORKS):
typescript
async retrieve({ id }: { id: number }) {
if (id) {
const sql = ${generateEnrichedTablesSql({ includeColumns: true, })} where tables.id = ${literal(id)};
// No schema filter applied - searches all schemas
}
}
Version v0.91.0+ (BUG):
typescript
async retrieve({
id,
name,
schema = 'public', //
}: {
id?: number
name?: string
schema?: string
}) {
const schemaFilter = schema ? filterByList([schema], []) : undefined
//
if (id) {
const idsFilter = filterByValue([id])
const sql = generateEnrichedTablesSql({
schemaFilter, //
includeColumns: true,
idsFilter,
})
}
}
The Problem:
The schema parameter has a default value of 'public'
When retrieving by ID, schemaFilter is always set to IN ('public')
The generated SQL filters by schema even though OID is globally unique
Tables in other schemas can never be found
Generated SQL (simplified):
sql
SELECT c.oid, c.relname, nc.nspname
FROM pg_class c
JOIN pg_namespace nc ON c.relnamespace = nc.oid
WHERE
nc.nspname IN ('public') --
AND c.oid IN (127071) -- But table is in 'directus' schema
-- Result: 0 rows → "Cannot find a table with ID 127071"
Proposed Fix
The schema filter should only be applied for name-based lookups, not ID-based:
typescript
async retrieve({
id,
name,
schema = 'public',
}: {
id?: number
name?: string
schema?: string
}) {
// Only apply schema filter when searching by name
const schemaFilter = (name && schema) ? filterByList([schema], []) : undefined
if (id) {
const idsFilter = filterByValue([id])
const sql = generateEnrichedTablesSql({
schemaFilter: undefined, // Don't filter schema for OID lookups
includeColumns: true,
idsFilter,
})
}
}
Why This Bug Went Unnoticed
Most Supabase Cloud users work primarily with the public schema (where it works)
Self-hosted users are a minority of the user base
The bug is "silent" - table listing works fine, only individual table retrieval fails
Tests likely only cover the public schema
No previous issue exists for this specific problem
Workaround
Downgrade to v0.84.2 in
docker-compose.yml
:
yaml
meta:
image: supabase/postgres-meta:v0.84.2
This workaround restores full functionality.
Test Case for Regression Prevention
typescript
test('retrieve table by ID works for non-public schemas', async () => {
// Setup: Create table in custom schema
await query('CREATE SCHEMA custom_schema')
await query('CREATE TABLE custom_schema.test_table (id serial PRIMARY KEY)')
const { rows } = await query(
"SELECT oid FROM pg_class WHERE relname = 'test_table'"
)
const tableOid = rows[0].oid
// Test: Retrieve by OID should work regardless of schema
const { data, error } = await pgMeta.tables.retrieve({ id: tableOid })
expect(error).toBeNull()
expect(data).toBeDefined()
expect(data.schema).toBe('custom_schema')
expect(data.name).toBe('test_table')
})
This bug prevents Studio from functioning correctly for self-hosted instances using custom schemas, which is a critical workflow for many users migrating from other systems (like Directus, as in my case).