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

"All object keys must match" error on Insert #26

Closed
billypap1 opened this issue Mar 31, 2022 · 13 comments
Closed

"All object keys must match" error on Insert #26

billypap1 opened this issue Mar 31, 2022 · 13 comments

Comments

@billypap1
Copy link

Hello, I have integrated Supabase-Swift to my project.
When I try to insert a row, I receive this error - > "All object keys must match"
Even if I include in my Codable Item values like id which is auto generated in db.

@srector13
Copy link

I get the same thing in my setup. Still trying to get around this issue

@billypap1
Copy link
Author

@srector13 Please inform me if you find any workaround

@billypap1
Copy link
Author

billypap1 commented Apr 1, 2022

@srector13 I found a workaround:

Let's suppose you have this code:

struct Todo: Codable {
var text: String
var integerval: String (make int to String)
var boolval: String (make bool to string)
}

let todo = Todo(text: "Example todo!", integerval: String(123) , boolval: "false")

let jsonData: Data = try JSONEncoder().encode(todo)
let jsonDict = try JSONSerialization.jsonObject(with: jsonData, options: .allowFragments)

client.database.from("todos")
.insert(values: jsonDict as! [String:String])
.execute { results in
// Handle response
}

All you have to do is to convert the Codable's Item Structure to String for all inputs even if they are Boolean, Int etc.

@grdsdev
Copy link
Contributor

grdsdev commented Apr 1, 2022

Hey guys, thanks for reporting this, that workaround shouldn't be needed, let me take a look and go back to you once I have a solution.

Thanks!

@grdsdev grdsdev transferred this issue from supabase/supabase-swift Apr 1, 2022
@grdsdev
Copy link
Contributor

grdsdev commented Apr 1, 2022

@billypap1 and @srector13 can you point the supabase-swift library to the master branch and check if that solves your issues?

@billypap1
Copy link
Author

billypap1 commented Apr 1, 2022

@GRSouza I updated the package and tried with the 0.0.2 version, again the same issue -> "All object keys must match" .
Only If I set my values to String works.

PS. I use this library for db operations, not supabase-swift

@grdsdev
Copy link
Contributor

grdsdev commented Apr 4, 2022

@billypap1 I've setup an integration tests along with a local supabase instance in the master branch of this repo, take a look at https://github.com/supabase-community/postgrest-swift/blob/master/Tests/PostgRESTIntegrationTests/IntegrationTests.swift and you should see that it's using a Codable object with non String attributes and its working.

Can you provide a sample project that contains the issue you're having? Or point me at your project if it's public. That way I can clone it and debug it on my machine.

@steve-chavez
Copy link

FYI, we worked around this issue on postgrest-js with supabase/postgrest-js#175.

@SergioB-dev
Copy link

SergioB-dev commented Apr 16, 2022

FWIW I just put this package PostgREST 0.0.2 into my iOS project and I get the same error.
Of the above proposed solutions the only one that is working is what @srector13 suggested as a workaround.

I would be happy to provide a sample project but at this point its literally the same thing as @srector13's suggestion

@richthornton
Copy link
Contributor

@GRSouza I was getting the same issue, and just tried the latest master (I'm new to Swift so had to look up how to install a package from a branch) and it worked great for me!

I followed the unit tests you linked above, which were super helpful as well (the new async await api is very nice 😍). Thanks so much!

@SergioB-dev
Copy link

@richthornton can you explain? Is 0.0.2 not the latest?

@richthornton
Copy link
Contributor

@SergioB-dev apologies, I presumed that the master branch had some additional changes than 0.0.2, but looking at the commits it seems like it's mostly additional test cases. I just tried 0.0.2, and it still works (for me at least) so its not difference between master and 0.0.2

The other change I made at the same time was changing the code to follow the format that was in the test cases. Using @billypap1's example above, the code would be:

struct Todo: Codable {
    var text: String
    var integer: Int
    var bool: Bool
}

let todo = Todo(text: "Example todo!", integer: 123, bool: false)

client.from("todos")
    .insert(values: todo)
    .execute { results in
        print("Response: \(results)")
    }

The difference is removing the json encoding and serialisation lines. When I try the two versions locally, this change seems to fix the issue for me. Hopefully it solves it for you as well 🤞. If not if you post another minimal reproduction I can try helping narrow down the differences between our setups.

@grdsdev
Copy link
Contributor

grdsdev commented Jun 2, 2022

I'll close this as it seems to be working with the latest package versions.

@grdsdev grdsdev closed this as completed Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants