Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upsert failing on non-null column, even though value exists in db #515

Open
2 tasks done
MaximusMcCann opened this issue Jan 25, 2024 · 2 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@MaximusMcCann
Copy link

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

I want to bulk update, but must use upsert. I use upsert but receive issues on non-null columns when they are not provided, despite the value existing on the record in the db.

To Reproduce

Example table:

CREATE TABLE test_table (
  id text primary key,
  other_column text null,
  name text not null --<--- The problem
);

INSERT INTO test_table (id, other_column, name)
VALUES ('id1',null,'some_name');

Updating a single row (via upsert): I know the record exists and the name column is populated. However if I try to upsert:

await supabase
.from('test_table')
.upsert([
{ id: 'id1', other_column: 'other_column_text' }
])

I receive

{
  code: '23502',
  details: 'Failing row contains (id1, other_column_text, null).',
  hint: null,
  message: 'null value in column "name" of relation "test_table" violates not-null constraint'
}

Expected behavior

The row show be "merged", thus it should just update the two columns I provided, and not default the name column to null, which in this case is not allowed.

  • OS: macOS
  • "@supabase/ssr": "^0.0.10",
    "@supabase/supabase-js": "^2.39.2",
  • Version of Node.js: v20.10.0
@MaximusMcCann MaximusMcCann added the bug Something isn't working label Jan 25, 2024
@MaximusMcCann MaximusMcCann changed the title Upsert failing on null value column, even though value exists in db Upsert failing on non-null column, even though value exists in db Jan 25, 2024
@evelant
Copy link

evelant commented May 8, 2024

I'm seeing very broken behavior with upsert, possibly related. I have a trigger that checks if the incoming NEW.version < OLD.version to reject updates from clients without the latest data. When I use upsert NEW.version is somehow set to the wrong value even though I've verified that the data I pass to upsert is correct! I pass { ...rest_of_record, version: 4 } to upsert and my trigger fails because NEW.version is 1 not 4.

@oddanderson
Copy link

I am seeing several issues with upsert as well. Is there a timeline on fixing this? There is no other good method for performing bulk row updates.

It's concerning that this issue has remained open this long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants