supabase-community / supabase-kt

A Kotlin Multiplatform Client for Supabase.
https://supabase.com/docs/reference/kotlin/introduction
MIT License
381 stars 37 forks source link

[Bug]: All object keys must match #589

Closed Deorigami closed 3 months ago

Deorigami commented 4 months ago

General Info

Version(s)

2.4.0

Kotlin Target(s) and their respective versions

2.0.0-Beta5

What happened? (include your code)

When i try to bulk upsert, it throws All object keys must match, hence i try to fill all the column with a value still throwing this exception, Screenshot 2024-05-10 at 05 55 06 but when i try to loop my list then upserting it 1 by 1 it doesnt throw anything

Steps To Reproduce (optional)

No response

Relevant log output (optional)

heres my chucker

URL: https://host_url/rest/v1/job_experience?on_conflict=id
Method: POST
Protocol: h2
Status: Complete
Response: 400 
SSL: Yes

Request time: Thu May 09 22:52:57 GMT 2024
Response time: Thu May 09 22:52:57 GMT 2024
Duration: 72 ms

Request size: 558 B
Response size: 85 B
Total size: 643 B

---------- Request ----------

Authorization: Bearer ***
Prefer: return=minimal,resolution=merge-duplicates,missing=default
Content-Profile: public
apikey: ****
X-Client-Info: supabase-kt/2.4.0
Accept: application/json
Accept-Charset: UTF-8
User-Agent: Ktor client
Content-Type: application/json

[
  {
    "position": "Test Row Edit Juga",
    "order": 0,
    "company_name": "Company",
    "start_date": "2024-05-09T09:55:33.062Z",
    "end_date": "2024-05-09T22:52:57.606283Z",
    "id": 15,
    "auth_ref": "86ca7b6b-1abe-447a-9e33-9ab32eedaf5c",
    "is_ongoing_job": true,
    "description": "123456",
    "created_at": "2024-05-09T09:55:49.034Z"
  },
  {
    "position": "Test Lagi",
    "order": 1,
    "company_name": "123123",
    "start_date": "2024-05-09T10:04:28.965Z",
    "end_date": "2024-05-09T22:52:57.606296Z",
    "id": 16,
    "auth_ref": "86ca7b6b-1abe-447a-9e33-9ab32eedaf5c",
    "description": "123123123",
    "created_at": "2024-05-09T10:04:37.607Z"
  }
]

---------- Response ----------

date: Thu, 09 May 2024 22:52:59 GMT
content-type: application/json; charset=utf-8
cf-ray: 881543583d0a5e96-CGK
cf-cache-status: DYNAMIC
strict-transport-security: max-age=15552000; includeSubDomains
sb-gateway-version: 1
x-envoy-upstream-service-time: 0
vary: Accept-Encoding
server: cloudflare
alt-svc: h3=":443"; ma=86400

{
  "code": "PGRST102",
  "details": null,
  "hint": null,
  "message": "All object keys must match"
}
jan-tennert commented 4 months ago

Can you try to use the defaultToNull parameter when upserting?

Deorigami commented 4 months ago

@jan-tennert where should i put this ?

Deorigami commented 4 months ago

Found it and still throwing same error @jan-tennert

Deorigami commented 4 months ago

Hey there idk why it's suddenly succeeded after several attempt with defaultToNull = true .. gonna try it more

Deorigami commented 4 months ago

The error shows up again .. so what i try to do is reordering a row .. first when first time insert the row .. the order will equal the id .. then i allow user to reorder the list .. afterthat i bulk upsert the new reordered list .. i do have 1 nullable column .. is that the problem ?

Screenshot 2024-05-10 at 21 35 52

URL: https://**/rest/v1/job_experience?on_conflict=id
Method: POST
Protocol: h2
Status: Complete
Response: 400 
SSL: Yes

Request time: Fri May 10 14:31:37 GMT 2024
Response time: Fri May 10 14:31:38 GMT 2024
Duration: 192 ms

Request size: 425 B
Response size: 85 B
Total size: 510 B

---------- Request ----------

Authorization: Bearer **
Prefer: return=minimal,resolution=merge-duplicates
Content-Profile: public
apikey:  **
X-Client-Info: supabase-kt/2.4.0
Accept: application/json
Accept-Charset: UTF-8
User-Agent: Ktor client
Content-Type: application/json

[
  {
    "position": "2",
    "order": 0,
    "company_name": "2",
    "start_date": "2024-05-10T14:31:25.636Z",
    "id": 41,
    "auth_ref": "86ca7b6b-1abe-447a-9e33-9ab32eedaf5c",
    "is_ongoing_job": true,
    "description": "",
    "created_at": "2024-05-10T14:31:25.636Z"
  },
  {
    "position": "1",
    "order": 1,
    "company_name": "1",
    "start_date": "2024-05-10T14:31:10.755Z",
    "id": 40,
    "auth_ref": "86ca7b6b-1abe-447a-9e33-9ab32eedaf5c",
    "description": "",
    "created_at": "2024-05-10T14:31:10.755Z"
  }
]

---------- Response ----------

date: Fri, 10 May 2024 14:31:39 GMT
content-type: application/json; charset=utf-8
cf-ray: 881aa2564f7abea7-CGK
cf-cache-status: DYNAMIC
strict-transport-security: max-age=15552000; includeSubDomains
sb-gateway-version: 1
x-envoy-upstream-service-time: 1
vary: Accept-Encoding
server: cloudflare
alt-svc: h3=":443"; ma=86400

{
  "code": "PGRST102",
  "details": null,
  "hint": null,
  "message": "All object keys must match"
}

My Chucker Record

grdsdev commented 4 months ago

Hi @jan-tennert and @Deorigami we had this issue in the other libraries too https://github.com/supabase/postgrest-js/issues/175

You must append a ?columns=collumn1,collumn2,collumn3 in the query param of the request.


The error is being thrown because the is_ongoing_job field is not sent on all objects.

jan-tennert commented 4 months ago

The error is being thrown because the is_ongoing_job field is not sent on all objects.

Yea, I assumed that was the problem, thanks for linking the fix. @Deorigami Can you try out version 2.4.1-dev and check if this issue was fixed?

Deorigami commented 4 months ago

@jan-tennert @grdsdev Thank you .. its working now

TiagoLira commented 4 months ago

@jan-tennert I am having this same issue on the insert request when inserting multiple rows. Maybe the fix can be applied on that method as well?

jan-tennert commented 4 months ago

@TiagoLira The newest versions should already include this fix.

TiagoLira commented 4 months ago

@jan-tennert I'm using the latest version (2.4.2). The fix was for the UPSERT request, I'm saying that the issue also happens on INSERT.

jan-tennert commented 4 months ago

@jan-tennert I'm using the latest version (2.4.2). The fix was for the UPSERT request, I'm saying that the issue also happens on INSERT.

Right, I will apply this fix there as well once I'm back from vacation. Reopening this as a reminder

jan-tennert commented 3 months ago

@TiagoLira Will be included in 2.5.0-beta-2