Skip to content

fix: onConflict parameter ignored in upsert #19

@jwelmac

Description

@jwelmac

Bug report

Describe the bug

The onConflict parameter is ignored in an upsert operation. Upserting a row only performs an update if the id is provided in the updated item and matches a previously inserted item.
This is due to the fact that the upsert handler only checks the id column to determine if an update should be performed.

To Reproduce

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

  1. Insert an item
     final data = {'user_id': 1, 'name': 'John Doe'};
      const table = 'users';

      // Insert a record
      await mockSupabase.from(table).insert(data);
  1. Update the data for that item
      final updatedData = {
        ...data,
        'name': 'James Bond',
      };
  1. Upsert the data specifying the onConflict column(s)
      await mockSupabase.from(table).upsert(
            updatedData,
            onConflict: 'user_id',
          );
  1. Select row based on expected unique column(s) returns multiple rows
      final usersAfterUpdate =
          await mockSupabase.from(table).select().eq('user_id', 1);
      print(usersAfterUpdate.length); // 2

Expected behavior

The onConflict parameter should be respected allowing updating an item based on a column(s) besides id.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions