supabase / supabase-flutter

Flutter integration for Supabase. This package makes it simple for developers to build secure and scalable products.
https://supabase.com/
MIT License
661 stars 154 forks source link

Upsert a list return exception #849

Closed fan123199 closed 3 months ago

fan123199 commented 3 months ago

Describe the bug

when upsert a list of data, if some data has primary id , and some data has no primary id, it will report error.

if all has id or all has no id, it return ok.

 var list = myAlbums
          .expand((element) => element.stickers)
          .map((e) {
        if (e.id != null) {
          return {
            "id": e.id,
            "user_id": supabase.auth.currentUser!.id,
            "sticker_id": e.sticker.id,
            "count": 8,
          };
        }
        return {
          "user_id": supabase.auth.currentUser!.id,
          "sticker_id": e.sticker.id,
          "count": 8,
        };
      }).toList();
      await supabase.from("user_sticker").upsert(list);

table definition

id | bigint | number |   sticker_id | text | string |   count | smallint | number |   user_id | uuid | string

error print

PostgrestException(message: null value in column "id" of relation "user_sticker" violates not-null constraint, code: 23502, details: Bad Request, hint: null)

Expected behavior It should be return OK

Version (please complete the following information): ├── supabase_flutter 2.3.4 │ ├── supabase 2.0.8 │ │ ├── gotrue 2.5.1 │ │ ├── postgrest 2.1.1 │ │ ├── realtime_client 2.0.1 │ │ ├── storage_client 2.0.1

Additional context Add any other context about the problem here.

dshukertjr commented 3 months ago

This is working as intended as primary keys are required to perform upsert.

fan123199 commented 3 months ago

well. the list of data that has no primary keys works well. That misled me. OK, I will do my work for two part, divide my list to 2 lists. and One insert , another one update, thanks for your reply