-
Notifications
You must be signed in to change notification settings - Fork 538
Open
Labels
bugSomething isn't workingSomething isn't workingpostgrest-jsRelated to the postgrest-js library.Related to the postgrest-js library.
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
When joining to an RLS-enabled table, we can get back nulls, even if the fkey column is required / non-nullable. However, the Typescript types represent the joined table as non-nullable, resulting in surprising app crashes when you receive a null row for a non-nullable relation.
If the joined table has RLS enabled, it should be typed as nullable, e.g. Profile | null, regardless of whether the fkey is nullable.
This would show an error to the developer, so they can decide to either handle the null rows or change to an inner join.
- We might be able to help with a PR if you can point us to where in the code this could be handled.
- Is there any other option, such as configuring our Supabase instance to default to inner joins?
- We're also considering bringing in a tool such as Zod that can detect and ignore null rows automatically, but this feels like a heavy-duty workaround to try to avoid issues like this in the future.
- Do you have any other ideas for making this more fool-proof?
To Reproduce
- Create Table1 with a non-null relation to Table2
- Enable RLS for Table2
- Query for table1 rows with nested table2 data
- The generated typescript types show that the nested table2 data is non-nullable
Expected behavior
- The generated typescript types should show that the nested Table2 data is nullable, due to RLS.
Screenshots
The current typing is incorrect for a default (outer) join:
To be clear, the current typing is correct for an inner join:
System information
- OS:
macOS Browser (if applies) [e.g. chrome, safari]- Version of supabase-js:
@supabase/[email protected] - Version of Node.js:
v23.0.0
Additional context
Possibly related to:
supabase/postgrest-js#546
etc.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingpostgrest-jsRelated to the postgrest-js library.Related to the postgrest-js library.