supabase / postgrest-js

Isomorphic JavaScript client for PostgREST.
https://supabase.com
MIT License
1.04k stars 133 forks source link

Cannot partially update table record with `not null` postgres domain #422

Closed cohlar closed 1 year ago

cohlar commented 1 year ago

Bug report

Describe the bug

The supabase client fails to update records from a table with a column defined as a domain with a not null constraint.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Create domain, table and seed data:
    
    create domain dimensions as real [] not null check (cardinality(value) = 3);

create table public.products ( id bigint primary key generated by default as identity, sku text unique not null check ("sku" <> ''), dimensions dimensions, archived boolean default false not null );

insert into public.products (sku, dimensions, archived) values ('sku-1', array [1,2,3], false);


2. Update the record from the supabase client:
```js
supabase.from('products').update({ archived: true }).eq('id', 1);
  1. See error: ""domain dimensions does not allow null values".

Expected behavior

The record should be updated with no error.

Screenshots

If applicable, add screenshots to help explain your problem. It doesn't seem to be a postgres restriction as the below SQL query works just fine:

update public.products set archived = true where id = 1;

System information

Additional context

For now, the below workaround works for me (move not null from the domain definition to the table column):

create domain dimensions as real [] check (cardinality(value) = 3);

create table public.products (
  id bigint primary key generated by default as identity,
  sku text unique not null check ("sku" <> ''),
  dimensions dimensions not null,
  archived boolean default false not null
);

insert into public.products (sku, dimensions, archived)
values ('sku-1', array [1,2,3], false);

The issue has also been posted on Discord.

cohlar commented 1 year ago

I just realized that the below works fine, so the issue is only with partial update of records.

supabase.from('products').update({ 
   id:1,
   sku: 'sku-1',
   dimensions: [1,2,3],
   archived: true ,
}).eq('id', 1);
gregnr commented 1 year ago

Hey @cohlar, strange that the partial update doesn't seem to be working for that column. I'm going to transfer this to the PostgREST JS repo.

steve-chavez commented 1 year ago
  1. See error: ""domain dimensions does not allow null values".

Can you post the full error message? Including code, details and hint keys.

cohlar commented 1 year ago

Sorry I am unable to reproduce the error. I reverted my dimensions domain back to not null and no longer get the error I used to get. I'm not sure exactly what happened in my database - I'll close this issue for now, if it ever re-occurs I'll follow up.