Open e-lobo opened 6 months ago
There may be a bigger problem with the library but just so you're aware, the supabase-js client will default to setting values to null when passing an array to upsert. Which can be fixed by setting defaultToNull
to false
https://supabase.com/docs/reference/javascript/upsert
Make missing fields default to
null
. Otherwise, use the default value for the column. This only applies when inserting new rows, not when merging with existing rows underignoreDuplicates: false
. This also only applies when doing bulk upserts.
I dont think this library exposes that capability unfortunately. For example this is how you do it using the js client directly:
await ctx.supabase.from("CollectionService").upsert(
services.map(({ id, ...service }, order) => {
const form = formatDbFields(service, nullableServiceFields);
const serviceId = Math.max(0, id);
return {
...(!!serviceId && { id: serviceId }),
name: service.name === null ? ServiceName.CUSTOM : service.name,
customName: service.name === ServiceName.CUSTOM && !!service.customName ? service.customName : null,
collectionId,
};
}),
{ defaultToNull: false }
);
I dealt with this last week using the js client directly so just wanted to share since it was fresh on my mind and might help with updating the library here :)
oh wait yes you can, that property is exposed in the fourth parameter
const upsert = useUpsertMutation(supabase.from("Team"), ["id"], "id", {
defaultToNull: false
})
Does something like that work? Also where is trigger
coming from? You should probably be using mutate
or mutateAsync
?
Does something like that work? Also where is
trigger
coming from? You should probably be usingmutate
ormutateAsync
?
i copy pasted some custom code so that how the trigger
came in my bad.
defaultToNull: false
this works nice šš
so something did change in supabase for this to be mandatory now š¤
great! glad that worked. Not quite sure, I started working with Supabase JS in January of this year and its been around since then š¤·
Describe the bug In the hook
useUpsertMutation
when we pass in the payload with an object with values undefined the columns are sent to supabase.Note: This was working before fine. Its recently that this broke.
To Reproduce Let me give you my use case.
Given the below schema
Notice how the id is autogenerated so it is not mandatory to be sent along in the payload.
So,
When we send
This fails with error
"null value in column \"id\" of relation \"NotificationLog\" violates not-null constraint"
Upon inspection of the network request i noticed that the column
id
is sent even though in the payload it is undefined.Im not sure why its failing suddenly out of the blue. Maybe something changed in supabase ? I'm not sure if its a bug here and am a little concerned of my usage of this mutation. Please advice