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 doesn't return data when row already exists #452

Open
2 tasks done
mrkpatchaa opened this issue Jul 25, 2023 · 4 comments
Open
2 tasks done

Upsert doesn't return data when row already exists #452

mrkpatchaa opened this issue Jul 25, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@mrkpatchaa
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

Hi Team, when doing an upsert on an existing record, the select returns an empty array.

To Reproduce

This is my code

const {data, error} = supabase
.from('chats')
.upsert(data, { onConflict: ['user_id', 'listing_id'], ignoreDuplicates: true })
.select()

Running this the first time returns data

{
  error: null,
  data: [
    {
      id: 7,
      created_at: '2023-07-25T19:19:03.942503+00:00',
      updated_at: '2023-07-25T19:19:03.942503+00:00',
      listing_id: 1,
      user_id: 'bf21737c-8684-49af-944c-94b126f90f55'
    }
  ],
  count: null,
  status: 201,
  statusText: 'Created'
}

Running it second time with the same values for listing_id and user_id returns

{
  error: null,
  data: [],
  count: null,
  status: 201,
  statusText: 'Created'
}

Expected behavior

The second call should return the same result as the first one.

Additional context

If the behaviour is normal, how should I get the id of the newly inserted / existing row? Typically I would run this code and redirect the user to the chat screen with id returned in data. The idea is to not make an extra call to the database.

@mrkpatchaa mrkpatchaa added the bug Something isn't working label Jul 25, 2023
@avi1737
Copy link

avi1737 commented Jul 26, 2023

Could you assign this issue to me? I would like to work upon this.

@mrkpatchaa
Copy link
Author

@avi1737 I cannot assign. Maybe an admin can help with that.

@steve-chavez steve-chavez transferred this issue from supabase/supabase Jul 27, 2023
@steve-chavez
Copy link
Member

.upsert(data, { onConflict: ['user_id', 'listing_id'], ignoreDuplicates: true })

IMO this behavior is pretty clear from the ignoreDuplicates: true usage, I don't see how it's a bug.

You should remove ignoreDuplicates or set it to false if you want the result to be returned.

@mrkpatchaa
Copy link
Author

@steve-chavez when I set ignoreDuplicates to false, I get this

{
  error: null,
  data: null,
  count: null,
  status: 201,
  statusText: 'Created'
}

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