-
Notifications
You must be signed in to change notification settings - Fork 262
Description
Describe the bug
Looking at the recurring 406 error and the code, I can explain the issue:
The error occurs because the query is expecting a single row (using .single() or .maybeSingle()), but it's getting no rows due to RLS policies or empty data.
The issue is in the UploadedDataQueries class where we're not handling empty results correctly. Here's what's happening:
The RLS policies are correct - they only allow users to access their own data based on the user_id in metadata
The error occurs when:
The table is empty
Or when the user has no data
Or when the user's ID doesn't match any records
Link to the blitz that caused the error
https://stackblitz.com/edit/sb1-6axihanc
Steps to reproduce
// 1. Sign in a user
const { data: authData, error: authError } = await supabase.auth.signInWithPassword({
email: '[email protected]',
password: 'password'
});
// 2. Try to insert data
const { data: insertData, error: insertError } = await supabase
.from('uploaded_data')
.insert({
type: 'test',
headers: ['col1', 'col2'],
rows: [],
metadata: { user_id: authData.user.id }
})
.select()
.single();
// 3. Try to fetch data
const { data: fetchData, error: fetchError } = await supabase
.from('uploaded_data')
.select('*')
.eq('metadata->user_id', authData.user.id)
.order('created_at', { ascending: false })
.limit(1);
The 406 error suggests that either:
The RLS policies are blocking access
The user ID in metadata doesn't match auth.uid()
The data format doesn't match expectations
Expected behavior
To reproduce the issue, let's follow these steps:
First, verify the database setup:
SELECT * FROM pg_policies WHERE tablename = 'uploaded_data';
Test the RLS policies with a sample user:
-- Set auth.uid() for testing
SET LOCAL ROLE authenticated;
SET LOCAL request.jwt.claim.sub = '00000000-0000-0000-0000-000000000000';
-- Try to insert data
INSERT INTO uploaded_data (
type,
headers,
rows,
metadata
) VALUES (
'test',
ARRAY['col1', 'col2'],
'[]'::jsonb,
jsonb_build_object('user_id', '00000000-0000-0000-0000-000000000000')
);
-- Try to select data
SELECT * FROM uploaded_data;
Test the API calls in the application:
// 1. Sign in a user
const { data: authData, error: authError } = await supabase.auth.signInWithPassword({
email: '[email protected]',
password: 'password'
});
// 2. Try to insert data
const { data: insertData, error: insertError } = await supabase
.from('uploaded_data')
.insert({
type: 'test',
headers: ['col1', 'col2'],
rows: [],
metadata: { user_id: authData.user.id }
})
.select()
.single();
// 3. Try to fetch data
const { data: fetchData, error: fetchError } = await supabase
.from('uploaded_data')
.select('*')
.eq('metadata->user_id', authData.user.id)
.order('created_at', { ascending: false })
.limit(1);
The 406 error suggests that either:
The RLS policies are blocking access
The user ID in metadata doesn't match auth.uid()
The data format doesn't match expectations
Parity with Local
- I have run the project in my local machine and I could not reproduce the issue.
Screenshots
Platform
Browser name = Chrome
Full version = 131.0.0.0
Major version = 131
navigator.appName = Netscape
navigator.userAgent = Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
performance.memory = {
"totalJSHeapSize": 75188391,
"usedJSHeapSize": 72304223,
"jsHeapSizeLimit": 2197815296
}
Hash = c8c182a3
### Additional context
**** I have deleted SupaBase Project and recreated through Bolt 2 times and after both configurations, it still ends up reproducing the same errors. I have attemtped to fix over a douzen times, Querried Gemini 2.0 Exp, GPT 1.o and Claude and even with there suggestions I have come up with nothing. ****

